Daniel@0: function index = subv2indMinka(siz,sub) Daniel@0: %SUBV2IND Linear index from subscript vector. Daniel@0: % SUBV2IND(SIZ,SUB) returns an equivalent single index corresponding to a Daniel@0: % subscript vector for an array of size SIZ. Daniel@0: % If SUB is a matrix, with subscript vectors as rows, then the result is a Daniel@0: % column vector. Daniel@0: % Daniel@0: % This is the opposite of IND2SUBV, so that Daniel@0: % SUBV2IND(SIZ,IND2SUBV(SIZ,IND)) == IND. Daniel@0: % Daniel@0: % See also IND2SUBV, SUB2IND. Daniel@0: Daniel@0: % Written by Tom Minka Daniel@0: Daniel@0: prev_cum_size = [1 cumprod(siz(1:end-1))]; Daniel@0: %index = (sub-1)*prev_cum_size' + 1; Daniel@0: index = sub*prev_cum_size' - sum(prev_cum_size) + 1;