help-octave
[Top][All Lists]

## no way for simple matrix lookup ?

 From: D. Goel Subject: no way for simple matrix lookup ? Date: Wed, 16 Jun 2004 10:56:17 -0400 User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.2 (gnu/linux)

```Hi

 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?

This "simple lookup" seems too fundamental that there should be a way
to do it.  Am I missing something?  Else, should this be a feature
request?

 if (1) above is not possible, is it possible if b = c ?

 More generally, the problem i am struggling with is:

A is a nxmxl matrix.  b and c are vectors.
I am looking for a vector D, such that D(i,:)= A(b(i), :, c(i)).

Any way to do that?

 A simple generalization of (1) to 3 D's possible?

D(i)=A(b(i), c(i), d(i)) ?

 BTW, i might be able to do (2) using the diag function, but is
there a way to use diag for 3 Dimensions?  or use diag such that it
acts only on 2 of the indices?  So one can implement (3), which is my
actual problem?

 Is there a way to transpose the 2nd and 3rd indices of a 3D
vector?  transpose() complains that it is implemented only for
2D's... I am trying 2.1.57.

Thanks, please CC if you can..
DG                                 http://gnufans.net/
--

-------------------------------------------------------------
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
-------------------------------------------------------------

```