[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Matrix like operations in a .oct file
From: |
babelproofreader |
Subject: |
Re: Matrix like operations in a .oct file |
Date: |
Sun, 6 Oct 2013 11:23:26 -0700 (PDT) |
Kai Torben Ohlhus-2 wrote
> On Fri, Oct 4, 2013 at 12:03 AM, babelproofreader <
> babelproofreader@
>> wrote:
>
>>
> <snip>
>>
>> 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 ;
>>
>>
> <snip>
>>
>
> Hello,
>
> 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:
> http://octave.sourceforge.net/doxygen/html/d3/d3f/classMatrix.html)
>
> 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.
>
> Best,
> Kai
>
> _______________________________________________
> Help-octave mailing list
> Help-octave@
> https://mailman.cae.wisc.edu/listinfo/help-octave
Matrix output (price.rows (), price.cols()); this doesn't change things. The
problem boils down to writing "result" to "output," i.e. output(ii,1) =
result ; // this writing to output matrix fails
--
View this message in context:
http://octave.1599824.n4.nabble.com/Matrix-like-operations-in-a-oct-file-tp4657812p4657953.html
Sent from the Octave - General mailing list archive at Nabble.com.