Prev: filter design in matlab
Next: moving average
From: Kevin Kleine on 19 Apr 2010 09:28 Matt... you're the man! Thanks! "Matt Fig" <spamanon(a)yahoo.com> wrote in message <hqa7l6$m8k$1(a)fred.mathworks.com>... > SUB2ind takes the size of the array as an input argument. If V may have the same number of elements as M has dimensions, use comma-separated list syntax by using NUM2CELL on V. For example: > > % Randomly dimensioned data > M = rand(cellfun(@(x) ceil(rand*2)+4,cell(1,ceil(rand*8)))); > V = ceil(rand(1,ndims(M))*3) > > % Index into M. > Vc = num2cell(V) > M(sub2ind(size(M),Vc{:}))
From: David Young on 19 Apr 2010 09:52
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <hqa7l6$m8k$1(a)fred.mathworks.com>... > SUB2ind takes the size of the array as an input argument. If V may have the same number of elements as M has dimensions, use comma-separated list syntax by using NUM2CELL on V. For example: > > % Randomly dimensioned data > M = rand(cellfun(@(x) ceil(rand*2)+4,cell(1,ceil(rand*8)))); > V = ceil(rand(1,ndims(M))*3) > > % Index into M. > Vc = num2cell(V) > M(sub2ind(size(M),Vc{:})) Matt: I don't understand the advantage of this over Vc = num2cell(V); M(vc{:}) |