[scilab-Users] matrix values extraction

Mike Page Mike at Page-One.Waitrose.com
Tue Jan 25 16:16:02 CET 2011


Hi,

I guess there are lots of ways to do it - not sure what's most efficient.
How about

-->diag(A(1:length(c),c))
 ans  =

    3.
    4.
    7.
    11.
    15.

That's at least quite compact...

Mike.


-----Original Message-----
From: Jean-Damien Capdeville [mailto:jdcapdeville at gmail.com]
Sent: 25 January 2011 14:32
To: users at lists.scilab.org
Subject: [scilab-Users] matrix values extraction


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




No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.872 / Virus Database: 271.1.1/3400 - Release Date: 01/24/11
07:35:00




More information about the users mailing list