How to delete all rows of an array that have a specified number in a particular column?
조회 수: 1 (최근 30일)
이전 댓글 표시
How can you delete a row of an array if the number in a particular column doesn't equal a specified number or even multiple numbers? For example, let A = magic(5). How can we delete any row where A(2,:) = 5? B=A(A(:,2)~=5) doesn't quite do it, only gives me the first column. In this case, there's only one row, but I'm looking for a general solution.
댓글 수: 0
채택된 답변
Walter Roberson
2022년 3월 30일
A(:, A(2,:) == 5) = [];
댓글 수: 2
Walter Roberson
2022년 3월 30일
How can we delete any row where A(2,:) = 5
A(2,:) is a query about contents of row 2, not about a particular column. It does not make sense to ask about removing rows for which something is true about row 2.
If you want to deal with columns, then
A = magic(5)
A(A(:,2) == 5, :) = []
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!