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