Problem 25. Remove any row in which a NaN appears
Solution Stats
Problem Comments
-
19 Comments
It's a good problem!
very good problem
ya.. but not so difficult though
nice trick with the " ' "))
very good problem
I really like this problem. It makes me to improve my solutions again and again. But it seems that I still use too many loops....
lol test case with transform was good one!
do not understand how one get so efficient solution on this (and to be honest other problems as well)
thanks you very much.
Why doesn't this work? It works when I use it on my computer...
function B = remove_nan_rows(A)
B = A;
B(any(isnan(A')),:) = [];
end
MATLABotic!
These types of problems are giving me so many useful functions
A(~sum(isnan(A),2),:) this workde for me
Cool!
Very good problem!
A easy problem if you know fuction isnan.
Nice one!
Oh
Easy one
Solution Comments
-
1 Comment
My solution is correct....i checked in MATLAB. You need to fix bugs
-
1 Comment
SHABI
-
1 Comment
I like problems with logic solutions.
-
1 Comment
two NaNs are not equal to each other, using isnan to detect NaNs. Thus,
a = a(all(a==a,2),:);
a = a(~any(isnan(a),2),:);
a(any(a~=a,2),:) = [];
a(any(isnan(a),2),:) = [];
-
1 Comment
really cool!
-
2 Comments
I think that test 4 does not comply to the question.
A(~sum(isnan(A),2),:) this worked for me
-
1 Comment
O(^-^) o
-
1 Comment
function B = remove_nan_rows(A)
B = A;
B(any(isnan(A')),:) = [];
end
Why isn't this working?
-
1 Comment
I like the solution
-
1 Comment
a = a(all(a==a,2),:); % a = a(~any(isnan(a),2),:);
a(any(a~=a,2),:) = []; % a(any(isnan(a),2),:) = [];
来自知乎
-
3 Comments
If I can't view a smaller solution, how can I improve myself ??
I really want to view the better answers.
The only improvement you can really make is making it one line
B = A( not( any(isnan(A), 2 ), :)
really?
-
2 Comments
I really liked this problem. I know that I took a very long approach to it but in time I hope to improve it. I have had a lot of practice with for and while loops which is why I have taken this approach.
i am unable to compare it with inf. how can i do that??
-
2 Comments
Can anyone tell me why matrix B is not being returned correctly? If I put it one 'end' further into the loop it returns the matrix each time a row is taken out and the tests fail
when you delete one row of B, the size of B changes.
your solution works with an assumption that the size of B won't change.
-
1 Comment
2 points better than my previous solution with ~any(isnan(
Passes the defined tests, but would fail if Inf was in the test matrices.
-
3 Comments
Can anyone please tell me how to reduce this size?
You already use vectorized assignment. Carry that further and get rid of the for loop.
The functions sum() and prod() can reduce row-wise to bring out NaN values. Thus, this express produces logicals for whether each row is in or out...
~isnan(prod(A,2))
-
2 Comments
Can anyone tell me, how it can coded in size of 10???
Using regexp, you can put all the code into a character string, and the character string only has a size of 1.
-
1 Comment
Good one...
-
3 Comments
Would fail if test suite contained any Infs.
^ Yes, this happens to work on the test inputs, but is technically not doing what the problem asks.
On the other hand, B = A(all(A==A,2),:) works.
Problem Recent Solvers7937
Suggested Problems
-
1588 Solvers
-
Make an awesome ramp for a tiny motorcycle stuntman
439 Solvers
-
454 Solvers
-
455 Solvers
-
513 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!