Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/KPMtools/subv2ind.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 function index = subv2ind(siz,sub) |
wolffd@0 | 2 %SUBV2IND Linear index from subscript vector. |
wolffd@0 | 3 % SUBV2IND(SIZ,SUB) returns an equivalent single index corresponding to a |
wolffd@0 | 4 % subscript vector for an array of size SIZ. |
wolffd@0 | 5 % If SUB is a matrix, with subscript vectors as rows, then the result is a |
wolffd@0 | 6 % column vector. |
wolffd@0 | 7 % |
wolffd@0 | 8 % This is the opposite of IND2SUBV, so that |
wolffd@0 | 9 % SUBV2IND(SIZ,IND2SUBV(SIZ,IND)) == IND. |
wolffd@0 | 10 % |
wolffd@0 | 11 % See also IND2SUBV, SUB2IND. |
wolffd@0 | 12 |
wolffd@0 | 13 %index = subv2indTest(siz,sub); |
wolffd@0 | 14 prev_cum_size = [1 cumprod(siz(1:end-1))]; |
wolffd@0 | 15 %index = (sub-1)*prev_cum_size' + 1; |
wolffd@0 | 16 index = sub*prev_cum_size' - sum(prev_cum_size) + 1; |
wolffd@0 | 17 |