How to compare two matrices in different sizes/dimensions ?

10 Ansichten (letzte 30 Tage)
Moses Tang
Moses Tang am 4 Apr. 2019
Kommentiert: Moses Tang am 4 Apr. 2019
Hi there,
I would like to compare two matrices in different sizes.
For example, matrix A is a 4x4 matrix ; matrix B is a 3x4 matrix
A = 1 1 1 1 (the same)
1 -1 1 -1
1 1 -1 -1 (the same)
1 -1 -1 1
B = 1 1 1 1 (the same)
1 1 -1 -1 (the same)
1 -1 -1 -1
In the example above, matrix A and B are in different sizes.
In terms of rows however, 1st and 3rd row of A is the same as 1st and 2nd row of B.
My goal is to create a new matrix C, that contains the same rows after the comparision.
C = 1 1 1 1
1 1 -1 -1
Is there a method in terms of matlab that could perform such function?

Akzeptierte Antwort

Guillaume
Guillaume am 4 Apr. 2019
Bearbeitet: Guillaume am 4 Apr. 2019
C = intersect(A, B, 'rows') %possibly with the 'stable' option if ordering matters.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays 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