How to remove particular rows from a matrix?
조회 수: 1 (최근 30일)
이전 댓글 표시
I need to remove particular row from a matrix A but only once, example:
A=[1 2 3 4; 1 2 3 4; 1 2 3 4; 1 1 1 1; 7 8 9 0]; y=[1 2 3 4; 1 1 1 1]; %the rows [1 2 3 4] in y occurs 3 times in A, I want to remove it only once
so setdiff(A,y, 'rows'); wont work.
But I need something general that works for arbitrary A and y
Thank you :)
댓글 수: 0
채택된 답변
Walter Roberson
2020년 2월 22일
편집: Walter Roberson
2020년 2월 22일
[found, idx] = ismember(y, A, 'rows');
A(idx(found). :) = []; %delete one copy of the found ones
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!