필터 지우기
필터 지우기

How to get nearest values in matrix and save indexes of these values?

조회 수: 1 (최근 30일)
I G
I G 2019년 5월 7일
편집: Stephen23 2019년 5월 7일
I have values saved as pi=[5 10 15].
And I have another values saved in puk, which is 401x1 double.
I need to find values in puk which are nearest to the values of pi, and as result I need to have indexes of that values in puk.
So I do not know how to search for nearest values in puk? And how to get indexes of these values?

채택된 답변

Stephen23
Stephen23 2019년 5월 7일
편집: Stephen23 2019년 5월 7일
>> X = [5,10,15];
>> Y = 0:7/5:30;
>> [~,Z] = min(abs(X-Y(:))) % the indices of the closest values:
Z =
5 8 12
>> Y(Z) % the corresponding values in Y:
ans =
5.6 9.8 15.4
For MATLAB versions before R2016b you will need to use bsxfun:
[~,Z] = min(abs(bsxfun(@minus,X,Y(:))))

추가 답변 (0개)

카테고리

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

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by