Nearest value from an array.

2 Ansichten (letzte 30 Tage)
Silpa K
Silpa K am 20 Sep. 2019
Kommentiert: Silpa K am 20 Sep. 2019
I have a set of numbers 'N'.I need to find each optimal nearest value of each N , from a series.
If M=[1,2,3,4,5,6,7,8,910] a series.
N=[0.5,1.3,2.4] .I need find the optimal nearest point of each N from M.
  2 Kommentare
Stephen23
Stephen23 am 20 Sep. 2019
@ Silpa K: please show us the expected output using your example vectors.
Silpa K
Silpa K am 20 Sep. 2019
like 1,2.If there are more numbers I need to find the optimal nearest points of each N.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 20 Sep. 2019
M=[1,2,3,4,5,6,7,8,910]
N=[0.5,1.3,2.4]
[~,ii] = min(abs(M(:) - N(:)'));
out = M(unique(ii));
  1 Kommentar
Silpa K
Silpa K am 20 Sep. 2019
Sir if I need to find two nearest values then how can I get.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by