A general slicing syntax

| categories: matlab, octave | View Comments

To slice the 4th cross section of the second dimension of a 3-dimensional array in Matlab/Octave, you would use a code like :

1: z=z(:,4,:);

If you want a bit more flexibility than that, you can have the sliced dimension as a parameter, using subsref :

1: dim=2;
2: idx.type='()';               
3: idx.subs={':',':',':'};
4: idx.subs{dim}=4;
5: z=subsref(z,idx);

Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.

org-mode source

blog comments powered by Disqus