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
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
回答(1 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!