How to compare the closest value in the matrix?

2 vues (au cours des 30 derniers jours)
rupak katwal
rupak katwal le 30 Oct 2019
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 commentaires
darova
darova le 31 Oct 2019
Can you show the result you expect to see?
Adam Danz
Adam Danz le 31 Oct 2019
The question isn't clear. As darova suggestion, some input/output pairs might be helpful in addition to another explanation of the problem.

Connectez-vous pour commenter.

Réponses (1)

Fabio Freschi
Fabio Freschi le 31 Oct 2019
% 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);

Catégories

En savoir plus sur NaNs dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by