[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #43098] "if (array)" inconsistent with matlab
From: |
Colin Macdonald |
Subject: |
[Octave-bug-tracker] [bug #43098] "if (array)" inconsistent with matlab (which is inconsistent with itself) |
Date: |
Thu, 28 Aug 2014 09:32:20 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 |
URL:
<http://savannah.gnu.org/bugs/?43098>
Summary: "if (array)" inconsistent with matlab (which is
inconsistent with itself)
Project: GNU Octave
Submitted by: cbm
Submitted on: Thu 28 Aug 2014 09:32:19 AM GMT
Category: Libraries
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Matlab Compatibility
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: dev
Operating System: GNU/Linux
_______________________________________________________
Details:
Personally, I think this should raise a warning, telling people we are
defaulting "if (all(array))". IMHO, "if (array)" is almost certainly a bug in
the user's code (she expected a scalar).
Nonetheless that is not what Matlab does. What they do is contradictory to
their docs. What their docs say is weird.
%% two easy cases
a = [1 1 1];
if (a), disp('got it right'); end
if (a), assert(true); else, assert(false); end
a = [1 0 1];
if (a), disp('got it wrong'); else, disp('got it right'); end
if (a), assert(false); else, assert(true); end
%% now the harder ones
a = [1 0+1i 1];
all(a)
if (a), disp('true??'); else, disp('false??'); end
a = [1 1+1i 1];
all(a)
if (a), disp('true, good'); else, disp('false, bad'); end
a = [1i 2i];
all(a)
if (a), disp('true??'); else, disp('false??'); end
%% Matlab:
% all of these give:
% error <Complex values cannot be converted to logicals>
% This contradicts their documentation as "help if" says:
% > The statements are executed if the real part of the
% > expression has all non-zero elements.
% (tested on 2008a and 2014a)
%% Octave:
% evaluates to true. Is this documented?
Please don't change it to Matlab's documented behaviour :)
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?43098>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Octave-bug-tracker] [bug #43098] "if (array)" inconsistent with matlab (which is inconsistent with itself),
Colin Macdonald <=