MATLAB Answers

Why the 'ismembertol' function fails on this 5 lines code?

2 views (last 30 days)
jie wu
jie wu on 5 Dec 2019
Answered: Guillaume on 9 Dec 2019
Tried to run this code
bb = [20 10
NaN NaN];
aa = [20 8
20 10];
[LIA,LOCB] = ismembertol(aa, bb,'ByRows', true);
But the following unexpected result was acquired.
LIA =
2×1 logical array
0
0
Then, if I revise matrix 'aa', and run the following code again, reasonable result can be get.
bb = [20 10
NaN NaN];
aa = [20 10];
[LIA,LOCB] = ismembertol(aa, bb,'ByRows', true);
>> LIA =
logical
1
Any corrections? Thank you!
Jie

  2 Comments

Guillaume
Guillaume on 5 Dec 2019
I'd say you've hit a bug in ismembertol. At the very least it doesn't behave as describe in the documentation.
The problem appears to be caused by the NaNs. So, to work around the problem you could remove nan rows.
You should raise a bug report with Mathworks.
Unfortunately, we can't really investigate the problem ourselves since ismembertol is a built-in function.
edit: I've raised a bug report, you should still do that if you want to be informed about the resolution
jie wu
jie wu on 6 Dec 2019
Thank you Guillaume for your comment and raising a bug report. I will revise my code to avoid those NaNs rows.

Sign in to comment.

Answers (1)

Guillaume
Guillaume on 9 Dec 2019
As per my comment, I raised a service request with Mathworks and they have confirmed that it is indeed a bug.
As the bug is not present when 'ByRows' is false (the default), they recommend to use:
all(ismembertol(aa, bb), 2)
instead of
ismembertol(aa, bb, 'ByRows', true)
This works as long as you don't need LocB. If you do need LocB, then I recommend you remove the NaNs from the arrays.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2017b