help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: extracting elements


From: Mike Miller
Subject: Re: extracting elements
Date: Sun, 1 May 2005 10:59:20 -0500 (CDT)

On Sat, 30 Apr 2005, Steve C. Thompson wrote:

How about this:

I=[1,2,5,4]';              % desired rows
J=[1,3;2,4;1,4;2,3];       % desired columns
X=reshape([1:20],4,5)';    % matrix to pull elements from

X1=X';

[Jr,Jc]=size(J);
[X1r,X1c]=size(X1);

a=(I-1)*X1r*ones(1,Jc);
Y=X1(J+a)


Thanks, Steve!  Is that the same as this?:

X(I*ones(1,size(J,2))+size(X,1)*(J-1))

It took me awhile, but that's what I came up with.

Let's see...

size(X,1)=X1c
size(J,2)=Jc

X(I*ones(1,Jc)+X1c*(J-1))

Well, it's hard to figure out. Your use of the transpose is throwing me off. If they both give the same answer, that's good enough for me!

Thanks again.

Mike



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]