[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #56692] Second output of ismember (S_IDX) is e
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #56692] Second output of ismember (S_IDX) is equivalent to "legacy" output in Matlab |
Date: |
Mon, 29 Jul 2019 00:42:11 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko |
URL:
<https://savannah.gnu.org/bugs/?56692>
Summary: Second output of ismember (S_IDX) is equivalent to
"legacy" output in Matlab
Project: GNU Octave
Submitted by: rik5
Submitted on: Sun 28 Jul 2019 09:42:09 PM PDT
Category: Octave Function
Severity: 2 - Minor
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: Any
_______________________________________________________
Details:
For the following code, Matlab returns [0, 0, 2, 1]
A = [5 3 4 2];
B = [2 4 4 4 6 8];
[~,ib] = ismember(A,B)
ib = [0, 0, 2, 1]
Octave, however, returns [0, 0, 4, 1].
The same result can be had in Matlab if the "legacy" option is used with
ismember (which uses the algorithm from Matlab versions prior to 2012b).
The difference is that when there are repeated, non-unique values in the set
B, Matlab returns the index of the first occurrence while Octave returns the
index of the last occurrence.
Debugging further in the ismember.m file, it is the call to lookup() which
returns the last index rather than the first index.
Changing lookup is a lot of work, and likely to have other consequences.
The problem could be worked around in the ismember.m file by sorting the input
set in descending order before calling lookup() and then returning
s_idx(tf) = (numel (tf) + 1) - is(s_idx(tf));
But, all of the manipulation seems like a lot of work just to get Matlab
compatibility on indices which still work for indexing.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?56692>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #56692] Second output of ismember (S_IDX) is equivalent to "legacy" output in Matlab,
Rik <=