How to compare the closest value in the matrix?

2 ビュー (過去 30 日間)
rupak katwal
rupak katwal 2019 年 10 月 30 日
回答済み: Fabio Freschi 2019 年 10 月 31 日
I have the three vectors from the reference values of one vector, i have to choose the closet value among other two vector?
suppose
if R is the reference vector
unknownM =0.8105 1.1581 0.6295 0.9594 0.8447 0.7103 0.8429 0.5372 0.9882 0.8924
then from the other two vector
sudoM =0.7768 1.1883 0.8918 0.6824 1.1393 0.6507 1.3433 1.2419 0.7456 1.1048
grepM = 0.8034 0.7853 1.0771 0.6649 0.5639 0.8384 0.6207 0.6000 0.6896 0.8011
for the first value of unkownM it should select the value of grepM an continous.
  2 件のコメント
darova
darova 2019 年 10 月 31 日
Can you show the result you expect to see?
Adam Danz
Adam Danz 2019 年 10 月 31 日
The question isn't clear. As darova suggestion, some input/output pairs might be helpful in addition to another explanation of the problem.

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

回答 (1 件)

Fabio Freschi
Fabio Freschi 2019 年 10 月 31 日
% your data
unknownM = [0.8105 1.1581 0.6295 0.9594 0.8447 0.7103 0.8429 0.5372 0.9882 0.8924];
sudoM = [0.7768 1.1883 0.8918 0.6824 1.1393 0.6507 1.3433 1.2419 0.7456 1.1048];
grepM = [0.8034 0.7853 1.0771 0.6649 0.5639 0.8384 0.6207 0.6000 0.6896 0.8011];
% preallocation
closest = zeros(size(unknownM));
% errors
errSudoM = abs(sudoM-unknownM);
errGrepM = abs(grepM-unknownM);
% sudoM is closer
idx1 = errSudoM < errGrepM;
closest(idx1) = sudoM(idx1);
% grepM is closer
closest(~idx1) = grepM(~idx1);

カテゴリ

Help Center および File ExchangeNaNs についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by