Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!s20g2000yqh.googlegroups.com!not-for-mail
From: Chris Maryan <kmaryan@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: 2D Array to Index a 3D Array?
Date: Fri, 21 Nov 2008 08:32:08 -0800 (PST)
Organization: http://groups.google.com
Lines: 21
Message-ID: <718c2ac0-bc91-4be9-8fc5-5a4fbd364596@s20g2000yqh.googlegroups.com>
NNTP-Posting-Host: 204.187.63.106
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1227285128 4505 127.0.0.1 (21 Nov 2008 16:32:08 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 21 Nov 2008 16:32:08 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: s20g2000yqh.googlegroups.com; posting-host=204.187.63.106; 
	posting-account=X7y8VwoAAABRatUHKb0_XV_h2SmGb2rK
User-Agent: G2/1.0
X-HTTP-Via: 1.0 MANU
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 
	2.0.50727),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:502334


Lets say I have a 3D array M (i.e. M(x,y,z))

I also have a 2D array J(x,y), where each element contains the z index
of interest in M. Can I use J to index into M without looping (i.e.
with a matlab indexing trick of some sort)?

i.e.
M(:,:,1) = [1,2;3,4];
M(:,:,1) = [21,22;23,24];

J = [1,2; 2,1];

D = M(:,:,J) % This doens't work, I'm looking for something that does
ans = [1  22
         23  4]

Any ideas? Thanks,

Chris