Using diagonal matrix as index
Søren Hauberg
soren at hauberg.org
Fri Jan 9 16:03:32 CST 2009
fre, 09 01 2009 kl. 16:47 -0500, skrev John W. Eaton:
> On 9-Jan-2009, Søren Hauberg wrote:
>
> | With a recent checkout I get the following IMHO quite odd behaviour:
> |
> | octave:18> A = magic (5)
> | A =
> |
> | 17 24 1 8 15
> | 23 5 7 14 16
> | 4 6 13 20 22
> | 10 12 19 21 3
> | 11 18 25 2 9
> |
> | octave:19> A (diag (true (1, 4))) = 4
> | A =
> |
> | 4 4 4 4 15
> | 23 5 7 14 16
> | 4 6 13 20 22
> | 10 12 19 21 3
> | 11 18 25 2 9
> |
> | Shouldn't this have produced an error since I'm using a 4x4 matrix as
> | index in a 5x5 matrix? Also, why are the elements placed in first row,
> | instead of along the diagonal?
>
> It's the same as if you had done
>
> A(find (diag (true (1, 4)))) = 4
>
> If we change this behavior, then people will likely complain when they
> try to run the code they wrote for the other leading brand in Octave.
> So if you think it is a bug, complain to those other guys.
Ohh, I see. I thought it would be the same as
A (full (diag (true (1, 4)))) = 4
which produces an error with the current code. So, I guess the bug is
that 'full' changes the class of diagonal matrices into 'double':
octave:28> class (diag (true (1, 4)))
ans = logical
octave:29> class (full (diag (true (1, 4))))
ans = double
I would assume that the latter should have produced 'logical'.
Søren
>
> jwe
More information about the Bug-octave
mailing list