MATLAB Answers

JL
0

reduce rows of a due to b

Asked by JL
on 30 Aug 2019
Latest activity Answered by Jos (10584)
on 30 Aug 2019
Hi everyone, I have 2 matices, A and B
a = [0 1 0
0 1 1
1 0 1
1 1 1];
b =[1 1 1
0 1 1];
Is it possible to reduce a using b?

  2 Comments

madhan ravi
on 30 Aug 2019
Expected result?
JL
on 30 Aug 2019
c = [0 1 0
1 0 1];
Sorry to include it

Sign in to comment.

2 Answers

madhan ravi
Answer by madhan ravi
on 30 Aug 2019
 Accepted Answer

ix = ismember(a,b,'rows');
a(ix,:) % gives you the rows in a which is common to b and ~ix vice versa

  3 Comments

JL
on 30 Aug 2019
Is is possible to get this?
c = [0 1 0
1 0 1];
madhan ravi
on 30 Aug 2019
Did you see the comment?
a(~ix,:)
JL
on 30 Aug 2019
great thanks!

Sign in to comment.


Answer by Jos (10584)
on 30 Aug 2019

You can simply use setdiff with the rows option ...
c = setdiff(a,b,'rows')

  0 Comments

Sign in to comment.