Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/KPMtools/ind2subv.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function sub = ind2subv(siz,index) |
matthiasm@8 | 2 %IND2SUBV Subscript vector from linear index. |
matthiasm@8 | 3 % IND2SUBV(SIZ,IND) returns a vector of the equivalent subscript values |
matthiasm@8 | 4 % corresponding to a single index into an array of size SIZ. |
matthiasm@8 | 5 % If IND is a vector, then the result is a matrix, with subscript vectors |
matthiasm@8 | 6 % as rows. |
matthiasm@8 | 7 |
matthiasm@8 | 8 %sub = ind2subvTest(siz, index); |
matthiasm@8 | 9 n = length(siz); |
matthiasm@8 | 10 if n==0, sub = index; return; end % added by KPM 17 Nov 07 |
matthiasm@8 | 11 cum_size = cumprod(siz(:)'); |
matthiasm@8 | 12 prev_cum_size = [1 cum_size(1:end-1)]; |
matthiasm@8 | 13 index = index(:) - 1; |
matthiasm@8 | 14 sub = rem(repmat(index,1,n),repmat(cum_size,length(index),1)); |
matthiasm@8 | 15 sub = floor(sub ./ repmat(prev_cum_size,length(index),1))+1; |
matthiasm@8 | 16 |
matthiasm@8 | 17 % slow way |
matthiasm@8 | 18 %for dim = n:-1:1 |
matthiasm@8 | 19 % sub(:,dim) = floor(index/cum_size(dim))+1; |
matthiasm@8 | 20 % index = rem(index,cum_size(dim)); |
matthiasm@8 | 21 %end |
matthiasm@8 | 22 |