Mercurial > hg > smallbox
comparison DL/RLS-DLA/private/diag_ids.m @ 60:ad36f80e2ccf
(none)
author | idamnjanovic |
---|---|
date | Tue, 15 Mar 2011 12:20:59 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
59:23f9dd7b9d78 | 60:ad36f80e2ccf |
---|---|
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 |