bugGNU Octave - Bugs: bug #47951, find complex number array elements...

 
 

bug #47951: find complex number array elements with condition

Submitter:  None
Submitted:  Wed 18 May 2016 03:03:30 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Wont Fix Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.0.2
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 18 May 2016 03:14:24 AM UTC, comment #1: 

Thanks for the bug report. This is a documented incompatibility with Matlab. There are few intentional incompatibilities, but this is one of them.

From the manual section "Comparison Operators"

For complex numbers, the following ordering is defined: z1 < z2 if and only if

  abs (z1) < abs (z2)
  || (abs (z1) == abs (z2) && arg (z1) < arg (z2))

This is consistent with the ordering used by max, min and sort, but is not consistent with MATLAB, which only compares the real parts.

https://www.gnu.org/software/octave/doc/interpreter/Comparison-Ops.html

So complex(-1,0) is not less than zero intentionally.

Mike Miller <mtmiller>
Group Member
Wed 18 May 2016 03:03:30 AM UTC, original submission:  

Hi,

Finding elements with a condition from an array with complex numbers works differently between matlab and octave.

Here's an example


$ cat a.m
arr = [1, 2+1i, 3, 0, -1, -2]
arr(find(arr>0))

$ octave-cli a.m
arr =

   1 + 0i   2 + 1i   3 + 0i   0 + 0i  -1 + 0i  -2 + 0i

ans =

   1 + 0i   2 + 1i   3 + 0i  -1 + 0i  -2 + 0i


Octave returns all elements but 0.

However, matlab doesn't include last two items in the result. It only returns 1, 2+1i, 3.

The following code returns same result in both


arr = [1, 2+1i, 3, 0, -1, -2]
arr(find(real(arr)>0))


Regards,
Louis

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-05-18 mtmiller StatusNone Wont Fix
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code