annotate examples/private/diag_ids.m @ 1:7750624e0c73 version0.5

(none)
author idamnjanovic
date Thu, 05 Nov 2009 16:36:01 +0000
parents
children
rev   line source
idamnjanovic@1 1 function id = diag_ids(x,k)
idamnjanovic@1 2 %DIAG_IDS Indices of matrix diagonal elements.
idamnjanovic@1 3 % ID = DIAG_IDS(X) returns the indices of the main diagonal of X.
idamnjanovic@1 4 %
idamnjanovic@1 5 % ID = DIAG_IDS(X,K) returns the indices of the K-th diagonal. K=0
idamnjanovic@1 6 % represents the main diagonal, positive values are above the main
idamnjanovic@1 7 % diagonal and negative values are below the main diagonal.
idamnjanovic@1 8
idamnjanovic@1 9
idamnjanovic@1 10 % Ron Rubinstein
idamnjanovic@1 11 % Computer Science Department
idamnjanovic@1 12 % Technion, Haifa 32000 Israel
idamnjanovic@1 13 % ronrubin@cs
idamnjanovic@1 14 %
idamnjanovic@1 15 % September 2006
idamnjanovic@1 16
idamnjanovic@1 17
idamnjanovic@1 18 if (nargin==1), k=0; end
idamnjanovic@1 19
idamnjanovic@1 20 [m,n] = size(x);
idamnjanovic@1 21 l = max(m,n);
idamnjanovic@1 22
idamnjanovic@1 23 if (k<=0)
idamnjanovic@1 24 id = (0:l-1)*m + (1:l) - k;
idamnjanovic@1 25 else
idamnjanovic@1 26 id = (0:l-1)*m + (1:l) + k*m;
idamnjanovic@1 27 end
idamnjanovic@1 28
idamnjanovic@1 29 if (l-k>m), id = id(1:end-(l-k-m)); end
idamnjanovic@1 30 if (l+k>n), id = id(1:end-(l+k-n)); end