Write code which replaces the number 1 with two NaNs.
X = [ 1 2 NaN 4 1 3 7 NaN 1 4 NaN 2]
Answer Y is
[ NaN NaN 2 NaN 4 NaN NaN 3 7 NaN NaN NaN 4 NaN 2]
The test-suite is incorrectly programmed. Isequal does not work for nan's:
isequal(nan,nan) is never true.
Furthermore, the line "if n=1" is an incorrect statement.
J.G. is right!! please correct it!
You can make use of 'isnan'
It can be solved...
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN...
the other commenters are right. see: http://www.mathworks.com/help/matlab/ref/isequalwithequalnans.html
Still, the open "if" statement in the test suite will not pass any solutions. Consider making "n" an argument?
the problem can be solved, but the test suite has bugs like everyone else commented. please fix the open "if" and isequal on NaN's i.e. assert(isequal(y_correct, y_correct)) does not pass in the second test.
Is it fine now?
Not quite. You will still need to use "isequalwithequalnans" (or "isequaln" in newer versions) instead of "isequal".
I updated the test suite with the suggestions made here. I believe it works now.
The particular number is 1
This problem would be much better if the "particular number" was one of the arguments to the function.
I wrote this solution when there were multiple problems with the test suite. It's an ugly hack, and not a "real" solution. Now that the test suite is working, please ignore this solution.
Longest Divisor Run
Find best domino orientation
Find the hypotenuse
04 - Scalar Equations 2
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