Path: news.mathworks.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!news.mathforum.org!not-for-mail
From: Ross <fed.rossi@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: matrix manipulation
Date: Fri, 28 Nov 2008 16:02:47 EST
Organization: The Math Forum
Lines: 19
Message-ID: <26885583.1227906197694.JavaMail.jakarta@nitrogen.mathforum.org>
NNTP-Posting-Host: nitrogen.mathforum.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: support1.mathforum.org 1227906197 28312 144.118.30.135 (28 Nov 2008 21:03:17 GMT)
X-Complaints-To: news@news.mathforum.org
NNTP-Posting-Date: Fri, 28 Nov 2008 21:03:17 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:503708


Hi there,

I have a question regarding matrix manipulation. I am using a 'brute force' method, but I guess there might be a straightforward way to do this that I am not aware of.

Assume you have array A, s.t. [N1 N2 N3] = size(A).
Also, assume you have a vector p, s.t. N1 = length(p), whose entries are integers between 1 and N3.

You want to obtain a new matrix B, N1-by-N2 where the rows are selected using p.

Example:
A = [1 2;3 4];
A(:,:,2) = [10 20;30 40]
p = [1 2];

B = [1 2; 30 40];


Thanks!
Ross