How to Compare a Table within some Tolerance Values?

조회 수: 2 (최근 30일)
ercan duzgun
ercan duzgun 2021년 2월 15일
댓글: ercan duzgun 2021년 2월 15일
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.

채택된 답변

Alan Stevens
Alan Stevens 2021년 2월 15일
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);

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 2월 15일
cols = find(all(abs(x-table)<tolerance_table,1))

카테고리

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

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by