[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: no way for simple matrix lookup ?
From: |
Mike Miller |
Subject: |
Re: no way for simple matrix lookup ? |
Date: |
Wed, 16 Jun 2004 12:20:44 -0500 (CDT) |
On Wed, 16 Jun 2004, D. Goel wrote:
[1] Suppose A is a nxn matrix. And b and are vectors. How do i return
elements of A specified by b and c?
i.e. Want to return a vector D, such that
D(i) = A(b(i), c(i))
Is the only way to do that a for loop? Is that inefficient?
Do you mean that b and c contain integer values in the range between 1 and
n? You want for b and c to specify the rows and columns of A to retain?
D = A(b,c)
And your variable D will be a matrix with size(D)=[length(b), length(c)].
You can transform it into a vector using D=D(:), or you can do this:
D = reshape(A(b, c), length(b)*length(c), 1)
You don't have to loop over 'i'.
Best,
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
-------------------------------------------------------------
- no way for simple matrix lookup ?, D. Goel, 2004/06/16
- Re: no way for simple matrix lookup ?,
Mike Miller <=
- Re: no way for simple matrix lookup ?, D. Goel, 2004/06/16
- Re: no way for simple matrix lookup ?, Mike Miller, 2004/06/16
- Re: no way for simple matrix lookup ?, Quentin Spencer, 2004/06/16
- Re: no way for simple matrix lookup ?, Julius Smith, 2004/06/18
- Re: no way for simple matrix lookup ?, Julius Smith, 2004/06/18
- Re: no way for simple matrix lookup ?, Mike Miller, 2004/06/18
- Re: no way for simple matrix lookup ?, Julius Smith, 2004/06/18
- Re: no way for simple matrix lookup ?, Etienne Grossmann, 2004/06/16
- Re: no way for simple matrix lookup ?, Jonathan C. Webster, 2004/06/16