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
0 件のコメント
回答 (3 件)
Azzi Abdelmalek
2015 年 8 月 25 日
編集済み: Azzi Abdelmalek
2015 年 8 月 25 日
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'))=[]
0 件のコメント
setdiff(q,w,'rows','stable')
0 件のコメント
If preserving repeated rows q(i,:) is important, then,
idx=all( bsxfun(@eq,q,w), 2);
result=q(~idx,:);
0 件のコメント
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!