필터 지우기
필터 지우기

Is there any way to find the row with closest values in matrix with a given array values?

조회 수: 2 (최근 30일)
Dear expert,
I have an array (1mat.txt) and I want to check the closest row in the matrix (2mat.txt) with the array. In this 2mat.txt i have 5 rows (which can be seen with graph) but in principle I have bigger matrix like 50 rows or 100 rows. Kindly help me with this.
Thank you

채택된 답변

Torsten
Torsten 2022년 10월 4일
편집: Torsten 2022년 10월 4일
How do you define "closest" ? The Euclidean distance between array and rows of the matrix ?
Then you can use
mat1 = [1.0000 0.1803 0.0779 0.0475 0.0369 0.0269 0.0208 0.0166 0.0093 0 0.0009 0.0008];
mat2 = [1 0 0 0 0 0 0 0 0 0 0 0
1.0000 0.1579 0.0244 0.0033 0 0 0.0003 0 0 0 0 0
1.0000 0.4389 0.1907 0.0842 0.0332 0.0169 0.0061 0.0049 0.0019 0 0 0
1.0000 0.5587 0.3522 0.2150 0.1275 0.0599 0.0423 0.0275 0.0099 0.0041 0.0038 0
1.0000 0.5728 0.3655 0.2707 0.1718 0.1064 0.0629 0.0337 0.0184 0.0132 0 0.0010];
[~,i] = min(vecnorm((mat2-mat1).'))
i = 2
  댓글 수: 5
Torsten
Torsten 2022년 10월 4일
Then you have the code already - it's my first answer.
SHUBHAM AGARWAL
SHUBHAM AGARWAL 2022년 10월 4일
Dear Torsten,
Thanks for the explanation of this method. It works.
Thank you very much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Directed Graphs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by