NaN selective removal from a matrix

조회 수: 5 (최근 30일)
Ziv Kassner
Ziv Kassner 2014년 7월 9일
답변: Andrei Bobrov 2014년 7월 9일
I have a matrix like this: a=[NaN NaN NaN NaN;NaN NaN NaN NaN;2 3 NaN 4;9 4 NaN 4;3 9 NaN 3];
and i want to remove all the rows that contains only NaN's to: b=[2 3 NaN 4;9 4 NaN 4;3 9 NaN 3];
please help me,
Ziv.

채택된 답변

Jos (10584)
Jos (10584) 2014년 7월 9일
tf1 = isnan(a)
tf2 = all(a,2)
tf3 = ~tf2
b = a(tf3,:)
b2 = a(~all(isnan(a),2),:) % in one giant leap

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 7월 9일
b = a(any(a == a,2),:);

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by