[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Minor MATLAB/Octave logical incompatibility
From: |
John W. Eaton |
Subject: |
Minor MATLAB/Octave logical incompatibility |
Date: |
Mon, 6 Sep 2004 09:57:17 -0400 |
On 5-Sep-2004, Randy Gober <address@hidden> wrote:
| Looking at the online MATLAB documentation for the logical command, I
| noticed this tidbit:
|
|
| "Most arithmetic operations remove the logicalness from an array. For
| example, adding zero to a logical array removes its logical characteristic.
| A = +A is the easiest way to convert a logical array, A, to a numeric double
| array."
| (From
| http://www.mathworks.com/access/helpdesk/help/techdoc/ref/logical.html)
|
| However, Octave keeps the type as bool in this case, in the just realest
| 2.1.58, we have:
|
| octave:1> A=logical(eye(3));
| octave:2> islogical(A)
| ans = 1
| octave:3> A=+A;
| octave:4> islogical(A)
| ans = 1
| octave:5> islogical(eye(3))
| ans = 0
|
| (also verified using 'whos')
|
| I am not sure if this is a bug or a feature, but it is different from the
| way MATLAB does it.
Currently, Octave treats unary plus as a no-op in the parser. Should
we change this? It would mean that instead of having the parser
convert the unary plus to a no-op, a function to handle the unary plus
operation would have to be defined for every octave_value class that
needs unary plus. Hmm. I guess this may be needed anyway if we want
to support classes at the scripting language level which can overload
unary plus.
jwe