MATLAB Answers

0

i need to compare a matrix with a static table

Asked by Omar Almahallawy on 20 Jun 2019
Latest activity Answered by dpb
on 20 Jun 2019
Accepted Answer by dpb
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]

  0 Comments

Sign in to comment.

Tags

2 Answers

Answer by dpb
on 20 Jun 2019
 Accepted Answer

> [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.

  0 Comments

Sign in to comment.


Answer by Bjorn Gustavsson on 20 Jun 2019

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 Comment

so... can u give me an example on how to do that

Sign in to comment.