help-octave
[Top][All Lists]
Advanced

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

Re: oct-file: extract matrix row? element-wise multiplication?


From: David Bateman
Subject: Re: oct-file: extract matrix row? element-wise multiplication?
Date: Wed, 31 May 2006 10:49:57 +0200
User-agent: Mozilla Thunderbird 1.0.6-7.6.20060mdk (X11/20050322)

Olaf Till wrote:

>Hi,
>
>is there, in an oct-file, a way to get a specified row or column of
>a matrix returned (probably as a RowVector or ColumnVector) ---
>corresponding, e.g., to `matrix(1, :)' in an m-file?
>  
>
If it truly is a matrix and not an NDArray then something like

Matrix m = args(0).matrix_value();
// Extract the first row of the matrix
RowVector r = m.row(0);
//Extract the first column of the matrix
ColumnVector c = m.column(0);

However the corresponding function doesn't exist for NDArray's. You
could do something with index vectors, but it would be more efficient to
extract the desired elements directly. Though doing that and getting the
indexing right isn't easy. If you want to go the indexing way then the
thread

http://velveeta.che.wisc.edu/octave/lists/archive//help-octave.2005/msg00328.html

might help.

>Is there a function or operator (usable in oct-files) which
>corresponds to `.*' and `./' in m-files for element-wise operations
>between to vectors or between a vector and a scalar?
>  
>

// Multiply the matrix by itself element by element
Matrix m2 = product(m,m)

// Divide the matrix m2 by m (stupid example)
Matrix m3 = quotient(m2,m)

// Do the same for a vector
RowVector r2 = product(r,r);
RowVector r3 = quotient(r2,r);

Note there is a page on the wiki for this

http://wiki.octave.org/wiki.pl?CPPQuickReference

Regards
David

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

[Prev in Thread] Current Thread [Next in Thread]