Delete specific rows from a matrix

조회 수: 8 (최근 30일)
Ron
Ron 2014년 8월 18일
댓글: Joseph Cheng 2014년 8월 18일
Hi all,
i want to delete rows which with the values 1 in their columns, how can i do it ?
For example:
A= [7,7;2,2;1,1;3,3]
Becomes
A=[7,7;2,2;3,3]
Thank you !
P.s I've searched other posts before posting this .. couldn't find any help

채택된 답변

Joseph Cheng
Joseph Cheng 2014년 8월 18일
편집: Joseph Cheng 2014년 8월 18일
the use of the function any() can find where there are any numbers equal to one.
A= [7,7;2,2;1,1;3,3]
A(any(A==1,2),:)=[]
by using the dimension modifier in the any() function, i can return which rows or columns contain the logical 1 which is when A ==1.
  댓글 수: 2
Ron
Ron 2014년 8월 18일
Thank you ! what the '2' in the code line
A(any(A==1,2),:)=[]
stands for ?
Joseph Cheng
Joseph Cheng 2014년 8월 18일
oh.. sorry meetings all day. the two is the dimension modifier. if you check the help for the any ('>>help any') the 2 stands for rows and 1 stands for columns. similar to the sum() function where you can sum a matrix in the row or column directions based on the dimension parameter.

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

추가 답변 (1개)

Honglei Chen
Honglei Chen 2014년 8월 18일
편집: Honglei Chen 2014년 8월 18일
A(any(A==1,2),:) = []

카테고리

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