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

1 次查看(过去 30 天)
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 个评论
Guillaume
Guillaume 2019-12-5
编辑:Guillaume 2019-12-5
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 2019-12-6
Thank you Guillaume for your comment and raising a bug report. I will revise my code to avoid those NaNs rows.

请先登录,再进行评论。

回答(1 个)

Guillaume
Guillaume 2019-12-9
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.

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

产品


版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by