Find all values within a given tolerance of 0

조회 수: 17 (최근 30일)
Benjamin
Benjamin 2018년 11월 6일
댓글: Benjamin 2018년 11월 6일
I have a matrix, called "difference". "difference" is 139x101. I would like to output the column numbers (i.e. somewhere between column 1 and column 101), where a value exists (out of the 139) that is within say 0.01% of 0. Is there a way to do this? It would be great if it could output the actual value, and column index. Note that if more than 1 column meets criterion, I want to output both.
  댓글 수: 3
Stephan
Stephan 2018년 11월 6일
편집: Stephan 2018년 11월 6일
How much is 0.01% from 0 in your case? In the real world it is zero, but i think community knows what you mean. But you need to give a value to calculate 0.01%.
Benjamin
Benjamin 2018년 11월 6일
편집: Benjamin 2018년 11월 6일
Sorry the percentage tolerance does not really make sense. I met within a tolerance on the y-axis (not a percentage, but a finite value distance from 0).
I think this seems to work:
C = difference < 0.0001 & difference > -0.0001;
k = find(C);
l= k/density_ids;

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

채택된 답변

Guillaume
Guillaume 2018년 11월 6일
편집: Guillaume 2018년 11월 6일
Ignoring the 0.01% of 0 and assuming you want the location of elements whose absolute value is less than 0.01, simply:
[row, column] = find(abs(difference) < 0.01)
To get the corresponding values:
values = difference(sub2ind(size(difference), row, column));

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by