NaN selective removal from a matrix

3 次查看(过去 30 天)
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 中查找有关 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