i need to compare a matrix with a static table

조회 수: 1 (최근 30일)
Omar Almahallawy
Omar Almahallawy 2019년 6월 20일
답변: dpb 2019년 6월 20일
X= [11.9000 10.3000 9.5000
10.3000 8.7000 9.5000
9.5000 7.9000 9.5000
11.1000 9.5000 9.5000]
Y= [7.9 186.46
8.7 205.17
9.5 223.84
10.3 242.49
11.1 261.11
11.9 279.69]
Z=[7.9 196.39
8.7 216.11
9.5 235.79
10.3 255.45
11.1 275.07]
A=[9.5 247.74
10.3 268.4
11.1 289.03
11.9 309.62
12.7 330.19]
i need to comare the first column from X with the first column from Y
second column from X with the first column from Z
third column from X with the first column from A
and choose the corrsponding number from the second column from Y, Z and A correspondingly
RESULT =[279.69 255.45 247.74
242.49 216.11 247.74
223.84 196.39 247.74
261.11 235.79 247.74]

채택된 답변

dpb
dpb 2019년 6월 20일
> [interp1(Y(:,1),Y(:,2),X(:,1)) interp1(Z(:,1),Z(:,2),X(:,2)) interp1(A(:,1),A(:,2),X(:,3))]
ans =
279.6900 255.4500 247.7400
242.4900 216.1100 247.7400
223.8400 196.3900 247.7400
261.1100 235.7900 247.7400
>>
If you'll rearrange your naming scheme to use cell arrays or struct field names instead of multiple variables for A,Y,Z then you could write as a looping construct instead of duplicating same code with different variables.

추가 답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2019년 6월 20일
OK, how do you need to compare the first column of X with the first column of Y? Correlation? length of difference-vector? Angle between vectors? If you describe what you need to do answers will come that much easier.
After a little bit of inspection ot seems you need to find the most identical component? If this is so, I suggest that you have a look at min, abs, using those two function would help you solve the task for one element of X and one column of Y Z and A? Once you worked that out use loops to repeat that step for all components in X.
HTH
  댓글 수: 1
Omar Almahallawy
Omar Almahallawy 2019년 6월 20일
so... can u give me an example on how to do that

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

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by