Custom type subscript assignment

John W. Eaton jwe at octave.org
Wed Jul 22 11:10:14 CDT 2009


On 22-Jul-2009, r-j-k wrote:

| Hi, I'm close to finishing my custom matrix type. I have implemented
| subscript assignment and it works correctly:
| 
| octave:13> x = my_matrix([10, 9, 8]);
| octave:14> x(2)
| ans =  9
| octave:15> x(2) = 5
| x =
| 
|    10    5    8
| 
| However, when I make a copy of x, y = x, and try to assign to either y or x,
| the behaviour is as if x or y are undefined:
| 
| octave:16> x = my_matrix([10, 9, 8]);
| octave:17> y = x
| y =
| 
|    10    9    8
| 
| octave:18> y(2) = 5
| y =
| 
|    0   5
| 
| After the value of y is changed as above, I can correctly assign to x:
| 
| octave:19> x(2) = 5
| x =
| 
|    10    5    8
| 
| 
| I realise that y is not a deep copy and something related to that is
| probably causing my problem. I know that my subscript assign operator is not
| being called at all in the problematic case. Any ideas how to correct this? 

If you want help with some detail like this, I think your best bet is
to post the code so other people can try it out and (maybe) give you
somem help.

jwe


More information about the Help-octave mailing list