How to Compare a Table within some Tolerance Values?

3 Ansichten (letzte 30 Tage)
ercan duzgun
ercan duzgun am 15 Feb. 2021
Kommentiert: ercan duzgun am 15 Feb. 2021
Dear Matlab community, I would like to ask how can I compare some values in a table within some percentage fault tolerance?
For example assume that I have values of (column matrix). I am searching these x column matrix values in a table.
The table matrix is table=table=table=[ 25.10, 200.75, 25.05, 50, 25.05; 30.00, 50.75, 29.95, 80, 30.05; 50.20, 50.75, 40.30, 50, 40.30];
Therefore, the third column of the Table is acceptable for me. And I want to find its column number, locations in the table matrix.
My MATLAB codes would be:
x=[25.10;
30.00;
40.35];
table=[ 25.10, 200.75, 25.05, 50, 25.05;
30.00, 50.75, 29.95, 80, 30.05;
50.20, 50.75, 40.30, 50, 40.30];
I would like to find that the location of the third and fifth column: location=3;5 . I can find it using if command for each element of the matrix, but I wanted to ask if there is easier way.
The first column is not accpetable for me, because the last element is not equivalent with tolerance with the last element of x.
How can I find this? Thanks in advance.
PS: I found this similar question here: https://www.mathworks.com/matlabcentral/answers/302059-how-to-find-the-closest-values-with-tolerance-in-a-matrix-given-a-specific-value , but my question is different, because if I it, I also find first two elements of the first column. But I don't want it. All three elements of the matrix should be in the tolerance limit.
My code for it:
x=[25.10;
30.00;
40.35];
table=[ 25.10, 200.75, 25.05, 50, 25.05;
30.00, 50.75, 29.95, 80, 30.05;
50.20, 50.75, 40.30, 50, 40.30];
tolerance_table=table*(1/100)
abs(x-table)<tolerance_table
>> ans=
3×5 logical array
1 0 1 0 1
1 0 1 0 1
0 0 1 0 1
[ii,jj]=find(abs(x-table)<tolerance_table)
ii =
1
2
1
2
3
1
2
3
jj =
1
1
3
3
3
5
5
5
I don't want the first column included in the solutions. I want to find 3 and 5 only. Not 1.

Akzeptierte Antwort

Alan Stevens
Alan Stevens am 15 Feb. 2021
Here's one possibility
x=[25.10;
30.00;
40.35];
table=[ 25.10, 200.75, 25.05, 50, 25.05;
30.00, 50.75, 29.95, 80, 30.05;
50.20, 50.75, 40.30, 50, 40.30];
tolerance_table=table*(1/100);
d = abs(x-table)<tolerance_table;
c = find(sum(d)==3);

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 15 Feb. 2021
cols = find(all(abs(x-table)<tolerance_table,1))

Tags

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by