I have a matrix as following:
A = [0,0;0,0;800,1096;1097,1461;1462,1701]
The amount of rows with 0's can be different depending on the input.
I'm trying to remove all the rows with 0's.
I've tried many different related questions but can't seem to figure it out.
One of the latest solutions I tried is this:
rowsWithZeros = any(A==0,"all");
A = A(~rowsWithZeros,:);

댓글 수: 1

Torsten
Torsten 2023년 1월 17일
I'm trying to remove all the rows with 0's.
All rows where at least one element is 0 or all rows where all elements are 0 ?

댓글을 달려면 로그인하십시오.

 채택된 답변

Torsten
Torsten 2023년 1월 17일
편집: Torsten 2023년 1월 17일

1 개 추천

% First case (see above)
A = [0,0;0,0;800,1096;0,1461;1462,1701];
A( any(~A,2), : ) = [];
A
A = 2×2
800 1096 1462 1701
% Second case (see above)
A = [0,0;0,0;800,1096;0,1461;1462,1701];
A( all(~A,2), : ) = [];
A
A = 3×2
800 1096 0 1461 1462 1701

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

제품

릴리스

R2022b

태그

질문:

2023년 1월 17일

편집:

2023년 1월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by