Filter löschen
Filter löschen

Question about using ismembertol function

4 Ansichten (letzte 30 Tage)
Ali Sohrabi
Ali Sohrabi am 25 Jan. 2022
Kommentiert: Ali Sohrabi am 25 Jan. 2022
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?

Akzeptierte Antwort

Stephen23
Stephen23 am 25 Jan. 2022
Bearbeitet: Stephen23 am 25 Jan. 2022
"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 Kommentar
Ali Sohrabi
Ali Sohrabi am 25 Jan. 2022
Thanks for your great answer. I supposed that this tolerance is used as normal tolerance that we consider for comparing two numbers.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Voss
Voss am 25 Jan. 2022
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 Kommentar
Ali Sohrabi
Ali Sohrabi am 25 Jan. 2022
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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by