A general slicing syntax
February 19, 2015 at 11:16 AM | 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.