Deleting Rows in a matrix

4 views (last 30 days)
A
A on 13 Mar 2021
Commented: A on 16 Mar 2021
I have a matrix:
A=[1 2 3;
5 6 7;
9 3 5;
9 5 2;
0 6 2;
7 3 6;
3 5 9;
0 2 4];
And another matrix
P=[1 2 3;
9 3 5;
9 5 2;
0 2 4;
7 3 6];
How can I delete the rows in A that have same elements in P?
For example:
A=[5 6 7;
9 5 2;
0 6 2;
3 5 9];
So the same rows in P are deleted in A

Accepted Answer

Walter Roberson
Walter Roberson on 13 Mar 2021
A=[1 2 3;
5 6 7;
9 3 5;
9 5 2;
0 6 2;
7 3 6;
3 5 9;
0 2 4];
P=[1 2 3;
9 3 5;
9 5 2;
0 2 4;
7 3 6];
setdiff(A, P, 'rows', 'stable')
ans = 3×3
5 6 7 0 6 2 3 5 9

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!