i need to compare a matrix with a static table

1 view (last 30 days)
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]

Accepted Answer

dpb
dpb on 20 Jun 2019
> [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.

More Answers (1)

Bjorn Gustavsson
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

Categories

Find more on Entering Commands in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!