Problem 1048. Detect a number and replace with two NaN's
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.
Solution CommentsShow comments
Problem Recent Solvers188
Back to basics 21 - Matrix replicating
Simple equation: Annual salary
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!