Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 2D Array to Index a 3D Array?
Date: Fri, 21 Nov 2008 18:42:01 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 12
Message-ID: <gg6vdp$n3q$1@fred.mathworks.com>
References: <718c2ac0-bc91-4be9-8fc5-5a4fbd364596@s20g2000yqh.googlegroups.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227292921 23674 172.30.248.37 (21 Nov 2008 18:42:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 21 Nov 2008 18:42:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:502375


Chris Maryan <kmaryan@gmail.com> wrote in message <718c2ac0-bc91-4be9-8fc5-5a4fbd364596@s20g2000yqh.googlegroups.com>...

> 
> Any ideas? Thanks,

M(:,:,1) = [1,2;3,4];
M(:,:,2) = [21,22;23,24];
J = [1,2; 2,1];
[I1 I2]=ndgrid(1:size(M,1),1:size(M,2));
M(sub2ind(size(M),I1,I2,J))

% Bruno