필터 지우기
필터 지우기

Closest number problem in m-file

조회 수: 1 (최근 30일)
Yuli Hartini
Yuli Hartini 2017년 5월 12일
댓글: Yuli Hartini 2017년 5월 12일
I need more help..
I have script looks like this
A = [2 5 9 15];
f = input('Enter input : ');
[val, idx]=sort(abs(f-A));
[val, idx]=min(abs(f-A));
A(idx)
If the input I enter is 3
Of course the output of A(idx) was 2
But I want the value output are 5 (the second closest of 3).
As well as for different inputs.
Please help me..
Thanks before

답변 (1개)

KL
KL 2017년 5월 12일
[val, idx]=sort(abs(f-A));
A(idx(2))
  댓글 수: 3
KL
KL 2017년 5월 12일
편집: KL 2017년 5월 12일
true, I just copy pasted her code
Yuli Hartini
Yuli Hartini 2017년 5월 12일
Thank you guys..
This is very helpful.

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by