idamnjanovic@60: function id = diag_ids(x,k) idamnjanovic@60: %DIAG_IDS Indices of matrix diagonal elements. idamnjanovic@60: % ID = DIAG_IDS(X) returns the indices of the main diagonal of X. idamnjanovic@60: % idamnjanovic@60: % ID = DIAG_IDS(X,K) returns the indices of the K-th diagonal. K=0 idamnjanovic@60: % represents the main diagonal, positive values are above the main idamnjanovic@60: % diagonal and negative values are below the main diagonal. idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: % Ron Rubinstein idamnjanovic@60: % Computer Science Department idamnjanovic@60: % Technion, Haifa 32000 Israel idamnjanovic@60: % ronrubin@cs idamnjanovic@60: % idamnjanovic@60: % September 2006 idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: if (nargin==1), k=0; end idamnjanovic@60: idamnjanovic@60: [m,n] = size(x); idamnjanovic@60: l = max(m,n); idamnjanovic@60: idamnjanovic@60: if (k<=0) idamnjanovic@60: id = (0:l-1)*m + (1:l) - k; idamnjanovic@60: else idamnjanovic@60: id = (0:l-1)*m + (1:l) + k*m; idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: if (l-k>m), id = id(1:end-(l-k-m)); end idamnjanovic@60: if (l+k>n), id = id(1:end-(l+k-n)); end