[scilab-Users] matrix values extraction

Jean-Damien Capdeville jdcapdeville at gmail.com
Tue Jan 25 18:30:27 CET 2011


Thanks for your answers.
I like the diag(A(:,c)) solution (however it's slower than the first
proposed solution).

To continue this discussion, actually my initial wish was to do the same
thing with a structure.
Let's say I have the structure "st" with a field "f" such as:
st(1).f = [1 ; 4 ; 7 ; 10 ; 13];

st(2).f = [2 ; 5 ; 8 ; 11 ; 14];

st(3).f = [3 ; 6 ; 9 ; 12 ; 15];

and the same vector than previously
c = [ 3 ; 1 ; 1 ; 2 ; 3 ];

I want to extract the vector such as for the index i, extracted value =
st(c(i)).f(i)
and so get the same result than previously [ 3 ; 4 ; 7 ; 11; 15 ]


Do you have any idea to do it without having to reconstruct a matrix (such
as [st(1).f st(2).f st(3).f]) ?

Thanks,

JD

________________________________________
De : Frédéric Mabille [mailto:mabille at supagro.inra.fr] 
Envoyé : mardi 25 janvier 2011 15:59
À : users at lists.scilab.org
Objet : Re: [scilab-Users] matrix values extraction

and other idea is :

diag( a ( : , c ( : ) ) ) 

fred

Le 25 janv. 2011 à 15:32, Jean-Damien Capdeville a écrit :


Dear all,

I'm looking to extract from a matrix "A" one value for each line. The column
positions of the value to extract would be given by a vector "c".

Here is an example:
A = [ 1 2 3 ; 4 5 6 ; 7 8 9 ; 10 11 12 ; 13 14 15 ]

c = [ 3 ; 1 ; 1 ; 2 ; 3 ]

How can I get the resulting vector [ 3 ; 4 ; 7 ; 11; 15 ] ?

I'm currently using a loop which is obviously a time expensive solution with
large matrix.
Any ideas to get it more efficiently?

Thanks,


Jean-Damien








More information about the users mailing list