help-octave
[Top][All Lists]
Advanced

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

Re: Effectively selecting elements of a matrix


From: Jonathan C. Webster
Subject: Re: Effectively selecting elements of a matrix
Date: Sun, 28 Dec 2003 16:33:21 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 Netscape/7.1



Thomas Weber wrote:
Hello, my problem is as follows: I have a matrix A (size: 50x500) and two vectors (vec1, vec2) of length
32000. The elements of the vectors are indices for the matrix, i.e. if
vec1(4) = 5 and vec2(4) = 10, I want to select A(5,10) into a new
vector results_vec at position 4:
results_vec (4) = A(5,10)
My problem is how to create this new vector effectively:


Ravel the matrix A out into one long vector, A_vec, using fortran indexing if 
you want.
Then combine vec1 and vec2 into a single index vector into your A_vec.
 .
vec3 = vec1 + size(A)(1) * (vec2 - 1)

Finally, your new reordered vector A3_vec

A3_vec = A_vec(vec3)

I think thats right, but check it.

Jonathan






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