MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Todayinput -> matrix (n*m) with at least one element equal to NaN; output -> matrix(p*m), the same matrix where we deleted the entire line containing NaN;

278 correct solutions
185 incorrect solutions

Last solution submitted on Dec 19, 2014

2 players like this problem

1 player likes this solution

1 player likes this solution

2 Comments

rohit more
on 11 Mar 2013

function y = removeNaN(x)
[n m] = size(x);
for i = 1 : n
maxx = max(isnan(x(i,:)));
if maxx ~= 1
y = (x(i,:))
end
end
What is Wrong With THis Code CAn SomeOne Tell ME

Tim
on 11 Mar 2013

It looks like y will return only the last non-NaN row, instead of collecting all of them.

1 player likes this solution

1 Comment

Carlos Adrian Vargas Aguilera
on 1 Jul 2013

Very nice!!

1 Comment

@bmtran
on 9 Feb 2012

This solution doesn't necessarily work if there are any Inf elements in the matrix. Perhaps it would be best to add a test case where that is the case.

1 Comment