Problem 17. Find all elements less than 0 or greater than 10 and replace them with 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.440892098500626e16). It's small but it's enough to fail the isequal test.
16 is the first nonregexpsolution!
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

1 Comment
took me probably 20 seconds

1 Comment
THIS PROBLEM IS FANTASTIC!

1 Comment
function y = cleanUp(x)
y = x;
L=length(y);
for i=1:L
if (y(i)<0)(y(i)>10)
y(i)=NaN;
end
end
end

1 Comment
this hasn't been fixed?

1 Comment
good

1 Comment
l

1 Comment
I reduce my code size with the help in this page.
http://matlabtricks.com/post16/thebackgroundofcodysolutionshavingextremelylowsize.
Besides, leading solution is a cheater.

1 Comment
very easy

1 Comment
Nicely done!

2 Comments
How can I make it shorter?
You could remove the 1's:
i= 1:length(x)
and
x(i)<0  x(i)>10
Also, it's probably best to use numel instead of length.

1 Comment
First non trivial one, learned a new trick

2 Comments
Any suggestion on how to reduce the size?
x(x < 0  x > 10) = NaN // use this it will reduce code size

3 Comments

1 Comment
This is called logical indexing

1 Comment
good

1 Comment
No need of colon operator...

6 Comments
How does the cleanup function work? I did not find a good explanation, but would be interested in how it works.
I don't understand how this size is possible. Even something as simple as y=x+1; has size 12 according to "About Cody" page! Kind of mystery for me...
So I googled and found an explanation here http://matlabtricks.com/post16/thebackgroundofcodysolutionshavingextremelylowsize
So it is indeed a sort of cheating? I wonder why it is allowed...
So do I. Wonder, I mean.
Thank you for the solution of the extremely low size solution
It's ironic. The size metric is meant to create most elegant solutions. At the same time it's more fun this way.

1 Comment
Straight forward with a for loop. Could definitely be improved considering good code doesn't use loops.

1 Comment
Checkout the builtin function "regexp"

1 Comment
this code works but its score is 51 and thats not good.... so can anyone improve it i'll be grateful.

1 Comment
are you ok?

1 Comment
There can be no elements with <0 AND >10. The problem statement should say <0 OR >10.

2 Comments
I can't understand why is it coming out wrong?? o.O
You would need a loop going through each element of x to finish this... a very bad idea..

1 Comment
hmmm

2 Comments
function y = cleanUp(x)
x=[5 17 20 99 3.4 2 8 6]
for i=1:8
if (x(i)<0x(i)>10)
y(i)=NaN;
else
y(i)=x(i);
end
end
Can anybody tell what is wrong with this code so that it is not clearing test 2.
Check this:Solution 181284.
x is input matrix which will vary rather being defined as in above program.

1 Comment
Ins't there an even easir way of doing this?

2 Comments
Brilliant
impressive!

1 Comment
Does not work because of rounding error

1 Comment
Inefficient code... My solution took 0.022746sec while this one took 0.255477. Although the size was 19...

1 Comment
It is working when I try!?
Problem Recent Solvers14642
Suggested Problems

36038 Solvers

1288 Solvers

Find the largest value in the 3D matrix
1369 Solvers

596 Solvers

397 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!