How to compare the closest value in the matrix?

2 次查看(过去 30 天)
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 个评论
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 CenterFile Exchange 中查找有关 NaNs 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by