merge two matrix based on x and y

I have two matrixes one has x and y coordinations in 2 first columns and elevaiton in the third and the other have x and y in 2 first column and temperature in the third column. Some data points may not be available in the other one and they are not in the same order. So I want to merge these two matrixes based on the x and y coordination values means finally I want to get a matrix with x and y for the first two columns and corresponding elevation and temperature for the 3rd and forth matrix.
the order should be like make a forth column for matrixA and add the third column of matrix B to Matrix A if the first and 2nd columns both matches.
ANy help will be apprecuiated

5 Comments

Please post a small complete example (inputs and desired output), showing how you would specifically deal with those points that do not have matching counterparts.
Can you give a very(!!!!) short example of the input (.e.g, two 4-by-3 arrays), the expected output arrays, and the relation between these arrays?
lets say thisis data 1:
data1 = [...13 34 5
14 35 5
1 36 6
2 43 10
3 42 8
5 44 10
6 36 1
7 33 0
8 32 3
1 31 4
9 30 6
5 28 1 ];
% and this is data 2:
data2 = [...
13 34 14
14 35 13
2 43 14
3 42 13
8 32 33
1 31 44
9 30 66
5 28 11]
I want my result to be like this:
13 34 14 5
14 35 13 5
2 43 14 10
3 42 13 8
8 32 33 3
1 31 44 4
9 30 66 6
5 28 11 1
Shouldn't this row [1 31 44 0] be this [1 31 44 4] ?
Yes exactly, sorry about that. Any idea for the solution?

Sign in to comment.

Answers (1)

Sounds like homework. Here's a hint:
data1 = [...13 34 5
14 35 5
1 36 6
2 43 10
3 42 8
5 44 10
6 36 1
7 33 0
8 32 3
1 31 4
9 30 6
5 28 1 ];
% and this is data 2:
data2 = [...
13 34 14
14 35 13
2 43 14
3 42 13
8 32 33
1 31 44
9 30 66
5 28 11]
[commonCoords, in1, in2] = intersect(data1(:, 1:2), data2(:, 1:2), 'rows')

Categories

Asked:

on 8 Feb 2019

Answered:

on 8 Feb 2019

Community Treasure Hunt

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

Start Hunting!