[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: subsetting matrices
From: |
John W. Eaton |
Subject: |
Re: subsetting matrices |
Date: |
Tue, 26 Oct 1999 19:06:57 -0500 (CDT) |
On 26-Oct-1999, address@hidden <address@hidden> wrote:
| On Tue, 26 Oct 1999, John W. Eaton wrote:
|
| > On 26-Oct-1999, address@hidden <address@hidden> wrote:
| >
| > | One of the beautiful things about octave is the ability to subset a matrix
| > | like
| > |
| > | Q = A(a:b,c:d);
| > |
| > | Now I need to do this in a dld (.oct file). Anyone know how to do this?
| >
| > It depends. What is the type of A? Is it an octave_value object or a
| > Matrix, or what?
|
| It's a matrix. I need to perform some operations on blocks of a matrix.
| This operation gets done very frequently in the optimization I'm doing so
| I'm trying to speed it up with a .oct file.
Here is an example of one way to do it:
#include <octave/config.h>
#include <octave/oct.h>
DEFUN_DLD (foo, args, ,
"y = foo (x, a, b, c, d): perform y = x(a:b, c:d)")
{
octave_value retval;
double a = args(1).double_value ();
double b = args(2).double_value ();
double c = args(3).double_value ();
double d = args(4).double_value ();
Matrix x = args(0).matrix_value ();
// This should work
//
// Matrix y = x.index (Range (a, b), Range (c, d));
//
// but for now, you have to write this:
idx_vector i (Range (a, b));
idx_vector j (Range (c, d));
retval = Matrix (x.index (i, j));
return retval;
}
jwe
---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL. To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------