[Top][All Lists]

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

Re: Matrix like operations in a .oct file

From: Kai Torben Ohlhus
Subject: Re: Matrix like operations in a .oct file
Date: Sun, 6 Oct 2013 17:02:42 +0200

On Fri, Oct 4, 2013 at 12:03 AM, babelproofreader <address@hidden> wrote:

the revelant part of my code is:-

 Matrix price = args(0).matrix_value () ; // a single column matrix
 Matrix output = args(0).matrix_value () ;

 // create intermediate calculation matrices
 Matrix vec_11 (1,11) ;
 Matrix price_11 (11,1) ;
 Matrix result (1,1) ;

 for ( int ii = -m ; ii < (m+1) ; ii ++ )
     vec_11 is filled in this loop and then doesn't change

 for ( octave_idx_type ii (50) ; ii < args(0).length () ; ii++ )
     // extract rolling window and perform matrix multiplication
     result = vec_11 * price.extract(ii-10,0,ii,0) ;
     output(ii,1) = result ; // this writing to output matrix fails

 retval_list(0) = output ;



Your code structure looks to me, that you want to perform the matrix manipulation in-place. You refer with price and output to the same input matrix. This is a problem. You are writing a function, that returns a matrix. For your case these two calls will be possible:

A = yourFunction (A);
B = yourFunction (A);

For the first case, there is no problem. But the second case gets weird. A and B refer to the same storage When you proceed in the command line, you wouldn't necessarily expect, that changes on B affect Matrix A as well. To avoid this better create a new output matrix in your *.oct-File (see:

Matrix output (price.rows (), price.cols());

If you need further help, could you please provide a more complete example? It is hard to guess where the problem is by this small excerpt.


reply via email to

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