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

(none)
author idamnjanovic
date Thu, 05 Nov 2009 16:36:01 +0000
parents
children
comparison
equal deleted inserted replaced
0:5181bee80bc1 1:7750624e0c73
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