How to delete entire row containing a certain value.

I am trying to delete all rows in matrix A that contain 'NaN' using the code below. A(any(isnan(A)),:)=[];
I used this code for A=[NaN 1 1; NaN 2 2; 1 NaN 1; 2 NaN 2], and the output for A was
A =
1 NaN 1
2 NaN 2
So the code successfully deleted the first two rows containing NaN, but not the last two. Why is this and how can I fix my code?

 채택된 답변

Kristina Chang
Kristina Chang 2013년 7월 10일

0 개 추천

It works! Thank you.

추가 답변 (1개)

Evan
Evan 2013년 7월 10일
편집: Evan 2013년 7월 10일
Does this work?
A(any(isnan(A),2),:) = []
It looks like your "any" function was operating column-by-column instead of row-by-row.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by