필터 지우기
필터 지우기

How to remove zero sum row from matrix

조회 수: 6 (최근 30일)
Vishal Sharma
Vishal Sharma 2017년 1월 24일
답변: Andrei Bobrov 2017년 1월 24일
A=[1 2 3 4 5 6;
0 0 1 1 0 1;
0 0 1 0 1 0]
Sum of second and third row if equal to zero, then in new matrix that column is to be excluded. So, the result shall be
A=[3 4 5 6;
1 1 0 1;
1 0 1 0]

채택된 답변

the cyclist
the cyclist 2017년 1월 24일
편집: the cyclist 2017년 1월 24일
colToRemove = sum(A(2:end,:))==0;
A(:,colToRemove) = [];
  댓글 수: 1
the cyclist
the cyclist 2017년 1월 24일
Edited my answer so that it will sum all rows except the first one.

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

추가 답변 (2개)

Roger Stafford
Roger Stafford 2017년 1월 24일
A = A(:,(A(2,:)+A(3,:)~=0));
  댓글 수: 1
Vishal Sharma
Vishal Sharma 2017년 1월 24일
Thanks Roger Stafford,,, if there are n rows, please also suggest answer...

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


Andrei Bobrov
Andrei Bobrov 2017년 1월 24일
A = A(:,sum(A(2:end,:))~=0);

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by