how to compare each elemnets in two cell with error tolerance?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Rishi Kiran Shankar
il 3 Lug 2019
Modificato: Stephen23
il 3 Lug 2019
Hi,
I have 1xn cells. Each cell many be of any size. I have to compare each element in (1x1 cell) with the next cell till ('1xn-1' cell) to ('1xn' cell). I cannot use 'ismember' function because, while comparing the elements, the error tolerence can be plus or minus 5%.
For eg,
a{1} = 1 2 3 a{2} = 1.05 5 1.9
The first elment in a{1} and a{2} is a match & second element in a{1} and third element in a{2} is a match.
Can anyone suggest me any idea?
Thanks in advance.
2 Commenti
Stephen23
il 3 Lug 2019
"the error tolerence can be plus or minus 5%"
According to your examples the tolerance is atleast 20%:
>> 1*1.2
ans = 1.2
>> 2*1.2
ans = 2.4
Risposta accettata
Stephen23
il 3 Lug 2019
Modificato: Stephen23
il 3 Lug 2019
>> A = {[1,2,3],[1.2,5,2.4]};
>> M = bsxfun(@rdivide,A{2},A{1}.');
>> [A1,A2] = find(abs(M-1)<=0.2) % 20%
A1 =
1
2
A2 =
1
3
EDIT: new 5% data:
>> A = {[1,2,3],[1.05,5,1.9]};
>> M = bsxfun(@rdivide,A{2},A{1}.');
>> [A1,A2] = find(abs(M-1)<=0.051) % 5% (and allow for floating point error)
A1 =
1
2
A2 =
1
3
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!