필터 지우기
필터 지우기

How to finding the second closest number in matrix?

조회 수: 2 (최근 30일)
Yuli Hartini
Yuli Hartini 2017년 1월 4일
편집: Adam 2017년 1월 4일
I have a matrix looks like this:
A = [1990;1993;1998;2001;2004 ]
and I would like to find the closest value to f=1999 (in this case the first closest value is certainly 1998), but how can I find the second closest value (2001) after I found the first value, and then find the third value (2004), etc.
Thanks

답변 (1개)

Adam
Adam 2017년 1월 4일
편집: Adam 2017년 1월 4일
[~,idx] = sort( abs( A - 1999 ) );
A( idx )
will give you all of them in order.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by