annotate Problems/private/diag_ids.m @ 13:cd55209c69e1

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