help-octave
[Top][All Lists]
Advanced

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

Re: oct function question


From: Anand Patil
Subject: Re: oct function question
Date: Sun, 01 Oct 2006 14:23:24 -0700
User-agent: Mozilla Thunderbird 0.9 (Macintosh/20041103)

Thanks for your responses, Paul and Søren.

Not sure I understand your question.  The matrix object owns the
data and there is no way to create a new matrix object which points
to existing data.  Two matrix objects can point to the same data,
but the data is copied if either are modified.


What I'd ultimately like to do is pass an output matrix into an oct function, manipulate it as a C array, and have the changes persist when the oct function terminates without any data copying at all (data in matrices are passed into oct functions by reference, correct?). Here's a bare-bones example:

----------------------oct function:--------------------------

DEFUN_DLD(change_matrix, args, , "Changes all the elements of a 2X2 matrix to 1")
{
   double* A = args(0).matrix_value().<<fortran_vec, data, etc.>>()
   for(int i=0; i<4; i++) A[i] = 1.0;
}

-------------------------Desired functioning in Octave:-------------------------------

octave:1> A = zeros(2);
octave:2> change_matrix(A)

A =

   1  1
   1  1

octave:3>
---------------------------------------------------------------------------

Could you recommend a best method for doing that?

Cheers,
Anand


reply via email to

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