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 件のコメント

Stephen23
Stephen23 2019 年 9 月 20 日
@ Silpa K: please show us the expected output using your example vectors.
Silpa K
Silpa K 2019 年 9 月 20 日
like 1,2.If there are more numbers I need to find the optimal nearest points of each N.

サインインしてコメントする。

 採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 9 月 20 日

0 投票

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 件のコメント

Silpa K
Silpa K 2019 年 9 月 20 日
Sir if I need to find two nearest values then how can I get.

サインインしてコメントする。

その他の回答 (0 件)

タグ

質問済み:

2019 年 9 月 20 日

コメント済み:

2019 年 9 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by