Problem 17. Find all elements less than 0 or greater than 10 and replace them with NaN
Given an input vector x, find all elements of x less than 0 or greater than 10 and replace them with NaN.
Example:
Input x = [ 5 17 -20 99 3.4 2 8 -6 ] Output y is [ 5 NaN NaN NaN 3.4 2 8 NaN ]
Solution Stats
Problem Comments
-
15 Comments
This is a poorly posed problem. There are no numbers that are both less than zero and greater than 10.
Just had the same thought as James Ross...
Fixed the wording to reflect this. Thanks for the comments.
come on wth is this problem i got wrong when i check my answer is true
Can someone explain this to me?
cleanUp=@(lb,x)interp1([lb 10],[lb 10],x);x=[5 17 -20 99 3.4 2 8 -6];y_correct=[5 NaN NaN NaN 3.4 2 8 NaN];
[isequalwithequalnans(cleanUp(1,x),y_correct),isequalwithequalnans(cleanUp(0,x),y_correct)]
That is, if i set the lower bound (lb) of the interpolation to 1 it passes the test code but if I set it to zero it fails with the same output!?!
The 3.4 in the result isn't the same in the two interpolations (diff= 4.440892098500626e-16). It's small but it's enough to fail the isequal test.
16 is the first non-regexp-solution!
good question
I have Assertion failure for the first test but it's good for the second --' I don't understand. Can you help me ?
More usefull than I thougth
useful basics
hay
cool problem!
goog
good problem to learn!
Solution Comments
Show commentsProblem Recent Solvers15540
Suggested Problems
-
Implement simple rotation cypher
1071 Solvers
-
360 Solvers
-
629 Solvers
-
349 Solvers
-
367 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!