How to exclude rows on the basis of specific entries?
조회 수: 50 (최근 30일)
이전 댓글 표시
채택된 답변
Guillaume
2018년 2월 6일
It's not clear what you mean by repeat.
If you mean you want to delete rows whose first four columns contain more than one 4:
A = [4 4 1 2; 4 4 4 4;1 4 2 4;4 2 3 2]
todelete = sum(A(:, 1:4) == 4, 2) > 1;
A(todelete, :) = []
If you mean you want to delete rows whose first four columns contain two more more consecutive 4, then it's a lot more complicated. One possible way
A = [4 4 1 2; 4 4 4 4;1 4 2 4;4 2 3 2]
todelete = cellfun(@(row) ~isempty(strfind(row, [1 1])), num2cell(A(:, 1:4) == 4, 2));
A(todelete, :) = []
추가 답변 (1개)
Jos (10584)
2018년 2월 6일
Here is a flexible example:
% data
X = [4 4] ; % rows starting with this should be discarded
A = [1 4 1 4 ; 4 4 2 2 ; 4 2 4 0 ; 4 4 4 4 ; 2 4 4 2] ; % rows 2 and 4 should be discarded
% engine
tf = ismember(A(:,1:numel(X)), X, 'rows')
A(tf) = [] ; % remove
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!