Mercurial > hg > smallbox
comparison util/ksvd utils/spdiag.m @ 70:c3eca463202d
(none)
author | idamnjanovic |
---|---|
date | Wed, 16 Mar 2011 14:16:57 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
69:5f1f436057ca | 70:c3eca463202d |
---|---|
1 function Y = spdiag(V,K) | |
2 %SPDIAG Sparse diagonal matrices. | |
3 % SPDIAG(V,K) when V is a vector with N components is a sparse square | |
4 % matrix of order N+ABS(K) with the elements of V on the K-th diagonal. | |
5 % K = 0 is the main diagonal, K > 0 is above the main diagonal and K < 0 | |
6 % is below the main diagonal. | |
7 % | |
8 % SPDIAG(V) is the same as SPDIAG(V,0) and puts V on the main diagonal. | |
9 % | |
10 % See also DIAG, SPDIAGS. | |
11 | |
12 | |
13 % Ron Rubinstein | |
14 % Computer Science Department | |
15 % Technion, Haifa 32000 Israel | |
16 % ronrubin@cs | |
17 % | |
18 % June 2008 | |
19 | |
20 | |
21 if (nargin<2) | |
22 K = 0; | |
23 end | |
24 | |
25 n = length(V) + abs(K); | |
26 | |
27 if (K>0) | |
28 i = 1:length(V); | |
29 j = K+1:n; | |
30 elseif (K<0) | |
31 i = -K+1:n; | |
32 j = 1:length(V); | |
33 else | |
34 i = 1:n; | |
35 j = 1:n; | |
36 end | |
37 | |
38 Y = sparse(i,j,V(:),n,n); |