필터 지우기
필터 지우기

Question about using ismembertol function

조회 수: 4 (최근 30일)
Ali Sohrabi
Ali Sohrabi 2022년 1월 25일
댓글: Ali Sohrabi 2022년 1월 25일
Hi there,
I have a question about using ismembertol function. I am working with this function, and now I am spotting out that something is going wrong with my calculation regarding this function. I show what is wrong in one small example.
Consider
A=[11538.0882247944, 21569.4133365453]
A = 1×2
1.0e+04 * 1.1538 2.1569
B=[ 11537.6120343925,21611.5704794796]
B = 1×2
1.0e+04 * 1.1538 2.1612
ismembertol(A,B, 10e-3,'ByRows',true)
ans = logical
1
I want to check whether A is a part of B or not? The result should show that A has not been found in B, but it says that it finds! Could you please help what I made a mistake here, or is it a bug in Matlab?

채택된 답변

Stephen23
Stephen23 2022년 1월 25일
편집: Stephen23 2022년 1월 25일
"The result should show that A has not been found in B...
You do not explain why you think that. I am guessing that you misunderstand the meaning of the third input.
Lets read the ISMEMBERTOL documentation, which describes the third input tol as: "Two values, u and v, are within tolerance if abs(u-v) <= tol*max(abs([A(:);B(:)]))". Now lets calculate this tolerance for your arrays:
tol = 10e-3;
A = [11538.0882247944, 21569.4133365453];
B = [11537.6120343925, 21611.5704794796];
T = tol*max(abs([A(:);B(:)]))
T = 216.1157
So we know that any values that are within 216.1157... of each other will be considered to be matching. Lets check how different your array values are:
A-B
ans = 1×2
0.4762 -42.1571
abs(A-B)<T
ans = 1×2 logical array
1 1
So the values you are comparing differ by much less than 216.1157..., and so ISMEMBERTOL correctly identifies them as matching. So far ISMEMBERTOL is working exactly as documented. You have not explained anywhere why you think is it not.
Regarding the third input tol:
  1. you provided a tol value of 10e-3, which is simpler written as 1e-2. Did you really mean 1e-3 ?
  2. perhaps you expect tol to be the tolerance used in the comparison. That is not the default behavior, but can be achieved very easily by reading the documentation and specifying DataScale = 1.
  댓글 수: 1
Ali Sohrabi
Ali Sohrabi 2022년 1월 25일
Thanks for your great answer. I supposed that this tolerance is used as normal tolerance that we consider for comparing two numbers.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Voss
Voss 2022년 1월 25일
Note that 10e-3 = 1e-2. Maybe that is the problem
A=[11538.0882247944, 21569.4133365453]
A = 1×2
1.0e+04 * 1.1538 2.1569
B=[11537.6120343925, 21611.5704794796]
B = 1×2
1.0e+04 * 1.1538 2.1612
ismembertol(A,B,10e-3,'ByRows',true)
ans = logical
1
ismembertol(A,B, 1e-3,'ByRows',true)
ans = logical
0
  댓글 수: 1
Ali Sohrabi
Ali Sohrabi 2022년 1월 25일
Thanks for your example. I tested it before and worked for this specific example but for other example it didn't. I think Stephen said the correct way of using tol value there.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by