selecting values of a vector

조회 수: 13 (최근 30일)
dav
dav 2013년 4월 2일
Hi,
Is there a way to pick the element of a vector which is closest to 1.
Let's say A = [ 113; 14; 6; 43; 9; 2 ]
I was wondering if there's a method to pick the value which is closest to 1. which in this case is = 2
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2013년 4월 2일
[minA, minidx] = min(abs(A - 1));
A(minidx)
  댓글 수: 1
dav
dav 2013년 4월 2일
thanks a lot!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by