comparison Problems/private/diag_ids.m @ 10:207a6ae9a76f version1.0

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