필터 지우기
필터 지우기

remove rows from a matrix on a specific condition

조회 수: 99 (최근 30일)
Dimitris
Dimitris 2013년 2월 1일
댓글: Jona Gladines 2020년 10월 12일
I want to remove rows from a matrix when a specific condition is satisfied.
For example, lets as assume that I have the following 5x5 matrix :
A= [ 5 3 3 1 4
6 6 3 1 0
6 2 2 2 0
4 2 3 2 0
1 1 1 1 2 ]
and I want to delete the rows of this matrix when the elements of the 5th column are equal to 0, so I will be left with the first and last row as an outcome:
A= [ 5 3 3 1 4
1 1 1 1 2 ]
Thanks
  댓글 수: 1
Dimitris
Dimitris 2013년 2월 1일
Just to make clear there are ; for every 5 elements in the example to separate the rows, I hope it is clear, sorry about that

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

채택된 답변

Daniell Algar
Daniell Algar 2013년 2월 1일
Try
A= [ 5 3 3 1 4; 6 6 3 1 0; 6 2 2 2 0; 4 2 3 2 0; 1 1 1 1 2 ]
A(A(:, 5)== 0, :)= []
  댓글 수: 3
Raghu Vamsi
Raghu Vamsi 2020년 1월 9일
What if the 0 is not exactly in the 5th Column but random in cells, then how to solve the same issue?
Jona Gladines
Jona Gladines 2020년 10월 12일
@Raghu Vamsi, If still needed, repeat for every column. As it wil only remove the rows with a 0 in that specific column.

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

추가 답변 (0개)

카테고리

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