How to compare the closest value in the matrix?

조회 수: 1 (최근 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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by