Given an input vector x, find all elements of x less than 0 or greater than 10 and replace them with NaN.
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];
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!
I have Assertion failure for the first test but it's good for the second --' I don't understand. Can you help me ?
this hasn't been fixed?
I reduce my code size with the help in this page.
Besides, leading solution is a cheater.
How can I make it shorter?
You could remove the 1's:
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
Tried using accumarray on an experimental basis... freaky awesome!!!
Learned from your Solution about accumarray -thanks for sharing it!
This is called logical indexing
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..
function y = cleanUp(x)
x=[5 17 -20 99 3.4 2 8 -6]
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?
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!?
Back to basics 20 - singleton dimensions
letter yes yes & letter no no
Make a run-length companion vector
Reverse a matrix
Is it really a 5?
Summing Digits within Text
Find relatively common elements in matrix rows
Make a checkerboard matrix
Knight's Tour Checker
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office