Path: news.mathworks.com!not-for-mail
From: "Darius " <martin@econ.ucsb.edu>
Newsgroups: comp.soft-sys.matlab
Subject: multidimensional indexing
Date: Tue, 13 May 2008 04:46:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 18
Message-ID: <g0b6eb$18j$1@fred.mathworks.com>
Reply-To: "Darius " <martin@econ.ucsb.edu>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210653963 1299 172.30.248.35 (13 May 2008 04:46:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 May 2008 04:46:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1266872
Xref: news.mathworks.com comp.soft-sys.matlab:468051


Hi,

I'm looking for a sort of generalization of diag for 
multidimensional arrays.  Specifically suppose I have:

A(:,:,1) = [1 2 3; 1 2 3; 1 2 3];

A(:,:,2) = [4 5 6; 4 5 6; 4 5 6];

A(:,:,3) = [7 8 9; 7 8 9; 7 8 9];

Is there a quick way to get

B = [1 5 9; 1 5 9; 1 5 9], so the first column of B is the 
first column of the first page, the second column is the 
second column of the second page, etc? (avoiding for 
loops) Thanks!