Filter löschen
Filter löschen

selecting values of a vector

4 Ansichten (letzte 30 Tage)
dav
dav am 2 Apr. 2013
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Apr. 2013
[minA, minidx] = min(abs(A - 1));
A(minidx)

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by