compare the column 2 of two matrix and forming the matrix with same entries in column 2 of Second Matrix.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have First Matrix A1 with 8 rows and 3 column, The 2 column of Matrix A1 and Matrix A2 have some same values. I want another matrix A3 which will have common Column 2 values and column 3 has same entries as in column 3 of matrix A1.
A1 =
[115.28 30 1
115.26 33 2
115.25 8 3
115.24 21 2
115.24 25 1
115.21 2 2
115.21 18 2
115.19 1 3]
2nd matrix
A2 =
[115.19 1 3
115.21 2 3
115.25 8 3
115.24 25 3
115.28 30 3
115.26 33 3]
I want output A3 as:
A3 =
[115.19 1 3
115.21 2 2
115.25 8 3
115.24 25 1
115.28 30 1
115.26 33 2]
0 Kommentare
Akzeptierte Antwort
Jan
am 19 Mär. 2022
A1 = [115.28 30 1; ...
115.26 33 2; ...
115.25 8 3; ...
115.24 21 2; ...
115.24 25 1; ...
115.21 2 2; ...
115.21 18 2; ...
115.19 1 3];
A2 = [115.19 1 3; ...
115.21 2 3; ...
115.25 8 3; ...
115.24 25 3; ...
115.28 30 3; ...
115.26 33 3];
[lA2, iA1] = ismember(A2(:, 1), A1(:, 1), 'legacy');
A3 = [A2(lA2, 1:2), A1(iA1, 3)]
The 'legacy' flag is required, because A1 contains the numer 115.24 twice. In legacy mode, the last occurrence is chosen, in normal mode (in modern Matlab versions), it is the first one.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices 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!