[scilab-Users] matrix values extraction

Samuel GOUGEON Samuel.Gougeon at univ-lemans.fr
Tue Jan 25 15:49:35 CET 2011


  Hello,

----- Message d'origine -----
De : Jean-Damien Capdeville
Date : 25/01/2011 15:32:
> 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 ] ?

[nL,nC] = size(A);
B = A.';
B((0:nL-1)*nC+c.') // gives you the expected result

> I'm currently using a loop which is obviously a time expensive solution with
> large matrix.
Indeed

Regards
Samuel




More information about the users mailing list