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 ?
More usefull than I thougth
THIS PROBLEM IS FANTASTIC!
function y = cleanUp(x)
y = x;
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:
x(i)<0 | 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
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 <0 AND >10. The problem statement should say <0 OR >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!?
Solve the set of simultaneous linear equations
Matrix with different incremental runs
Say something funny
Matlab Basics II - Minimum
Crop an Image
Given two arrays, find the maximum overlap
Find the palindrome
Swap the first and last columns
Return the 3n+1 sequence for n
Find the treasures in MATLAB Central and discover how the community can help you!
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