Accessing Arbitrary Dimensions

dbateman dbateman at free.fr
Sat Mar 1 14:31:10 CST 2008


I've dealt with pretty much the same issue in the past. The sub2ind method is
slow and not that flexible. I prefer two different solutions 

1) Create a cell array of the correct dimensionality like

idx = cell(ndim, 1)
for i = 1, ndim
  idx {i} = ":";
endfor
idx{dim} = ??;

where ?? is replaced with whatever you want to replace it with to act of the
dimension required. Then you can convert to a cs-list to use it as an index
like x(idx{:}).

2) use permute/ipermute to more the desired dimension to be the first
dimension and then treat the indexing as 2-D (even if the matrix is ND) and
then permute back

D.
-- 
View this message in context: http://www.nabble.com/Accessing-Arbitrary-Dimensions-tp15662826p15780584.html
Sent from the Octave - General mailing list archive at Nabble.com.



More information about the Help-octave mailing list