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 ]
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
this hasn't been fixed?
good
l
I reduce my code size with the help in this page.
http://matlabtricks.com/post-16/the-background-of-cody-solutions-having-extremely-low-size.
Besides, leading solution is a cheater.
very easy
Nicely done!
How can I make it shorter?
You could remove the 1's:
i= 1:length(x)
and
x(i)10
Also, it's probably best to use numel instead of length.
First non trivial one, learned a new trick
Any suggestion on how to reduce the size?
x(x < 0 | x > 10) = NaN // use this it will reduce code size
This is called logical indexing
good
No need of colon operator...
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/post-16/the-background-of-cody-solutions-having-extremely-low-size
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.
Straight forward with a for loop. Could definitely be improved considering good code doesn't use loops.
Checkout the built-in function "regexp"
this code works but its score is 51 and thats not good.... so can anyone improve it i'll be grateful.
are you ok?
There can be no elements with 10. The problem statement should say 10.
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..
hmmm
function y = cleanUp(x)
x=[5 17 -20 99 3.4 2 8 -6]
for i=1:8
if (x(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.
Ins't there an even easir way of doing this?
Brilliant
impressive!
Does not work because of rounding error
Inefficient code... My solution took 0.022746sec while this one took 0.255477. Although the size was 19...
It is working when I try!?
Matrix which contains the values of an other matrix A at the given locations.
188 Solvers
Detect a number and replace with two NaN's
155 Solvers
Who is the smartest MATLAB programmer?
443 Solvers
Matlab Basics - Create a row vector
192 Solvers
256 Solvers