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

조회 수: 1 (최근 30일)
jie wu
jie wu 2019년 12월 5일
답변: Guillaume 2019년 12월 9일
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