# How to inner join two matrices?

2 Ansichten (letzte 30 Tage)
Mohammed am 20 Okt. 2016
Kommentiert: Mohammed am 21 Okt. 2016
I have following two matrices of data that contain three columns each, first two columns are GPS data (latitude, longitude) and the third value is elevation angle. I would like to inner join both tables based on their GPS values to calculate the difference in elevation angle between the two matrices. Here is an example;
tbl1 = [
28.057 -80.621 25.3
......];
tbl2 = [
28.057 -80.624 20.6
28.057 -80.621 20.62
.....];
tbl3 should look like the following:
tbl3 = [
28.057 -80.621 25.3 20.6 4.7];
Any idea on how to join these tables? Cheers!
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Guillaume am 20 Okt. 2016
Bearbeitet: Guillaume am 21 Okt. 2016
[~, row1, row2] = intersect(tbl1(:, [1 2]), tbl2(:, [1 2]), 'rows');
tbl3 = [tbl1(row1), tbl2(row2, 3)];
tbl3(:, 5) = diff(tbl3(:, [4 3]), [], 2);
This assumes that the GPS values are exactly identical in both matrices or that they're rounded to the same number of decimals in both.
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Guillaume am 21 Okt. 2016
Bearbeitet: Guillaume am 21 Okt. 2016
Sorry, forgot to specify the dimension in diff (and got the wrong column destination). It should have read:
tbl3(:, 5) = diff(tbl3(:, [4 3]), [], 2);
Fixed now.
Mohammed am 21 Okt. 2016
Works like charm, however it is missing single parenthesis :). thanks again for sharing your knowledge.
tbl3(:, 5) = diff(tbl3(:, [4 3]), [], 2);

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Logical finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by