I would like to remove zeros from my matrix

조회 수: 1 (최근 30일)
Ashkan Rigi
Ashkan Rigi 2021년 10월 26일
답변: Walter Roberson 2021년 10월 27일
a=[0 0 0; 0 0 0; 1 2 3; 4 5 6]
  댓글 수: 3
LeoAiE
LeoAiE 2021년 10월 26일
편집: LeoAiE 2021년 10월 26일
a=[0 0 0; 0 0 0; 1 2 3; 4 5 6]
a = 4×3
0 0 0 0 0 0 1 2 3 4 5 6
a(a>0) % the results would be a column vector
ans = 6×1
1 4 2 5 3 6
% Or try to remove the row or the columns with zeros
a(1:2,:) = []
a = 2×3
1 2 3 4 5 6
a
a = 2×3
1 2 3 4 5 6
Rik
Rik 2021년 10월 27일
@Aladdin, this is an answer to what might be a homework question. Please consider either moving your comment to the answer section (by deleting this and reposting it) or deleting your comment.

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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 10월 27일
a = [0 0 0; 0 0 0; 1 2 3; 4 5 6]
a = 4×3
0 0 0 0 0 0 1 2 3 4 5 6
b = rmmissing(standardizeMissing(a, 0))
b = 2×3
1 2 3 4 5 6

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by