Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: multi-dimensional indexing
Date: Sat, 4 Feb 2012 11:23:32 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 19
Message-ID: <jgj4fk$lv3$1@newscl01ah.mathworks.com>
References: <jgh0rp$po9$1@newscl01ah.mathworks.com> <jgh82t$md7$1@newscl01ah.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1328354612 22499 172.30.248.47 (4 Feb 2012 11:23:32 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 4 Feb 2012 11:23:32 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:756723

"Steven_Lord" <slord@mathworks.com> wrote in message

> The approach I would use in this case is the comma-separated list approach, 
> though you may want to look at the implementation of the SUB2IND function 
> and write your own function, based on SUB2IND, that accepts a vector of 
> indices rather than individual vectors for the index in each dimension.
> 

That won't really solve the problem of avoid using comma-list, since SUB2IND again requires comma separated-list as input argument.

One way is doing something like this:

A = rand(3,4,5)
ind = [2 1 3]

s = size(A);
A ( 1+(ind-1)*cumprod([1 s(1:end-1)])' )

 % Bruno