delete certain rows from a matrix

I have two matrices and want to delete the rows of the first matrix which are identical to particular rows of the second matrix. For example, I have q = [1 0 0 0; 2 3 4 5; 6 7 8 9] and w = [1 0 0 0]. I want a generic command for q to become [2 3 4 5;6 7 8 9] , i.e., delete [1 0 0 0] from w

답변 (3개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 25일
편집: Azzi Abdelmalek 2015년 8월 25일

0 개 추천

q = [1 0 0 0; 2 3 4 5; 6 7 8 9]
w = [1 0 0 0]
q=setdiff(q,w,'rows')
or
q = [1 0 0 0; 2 3 4 5; 6 7 8 9]
w = [1 0 0 0]
q(ismember(q,w,'rows'))=[]
Matt J
Matt J 2015년 8월 25일
편집: Matt J 2015년 8월 25일

0 개 추천

setdiff(q,w,'rows','stable')
Matt J
Matt J 2015년 8월 25일
편집: Matt J 2015년 8월 25일

0 개 추천

If preserving repeated rows q(i,:) is important, then,
idx=all( bsxfun(@eq,q,w), 2);
result=q(~idx,:);

이 질문은 마감되었습니다.

태그

아직 태그를 입력하지 않았습니다.

질문:

2015년 8월 25일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by