selecting values of a vector

3 次查看(过去 30 天)
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)

更多回答(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