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.
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.
Problem Recent Solvers188
Arrange Vector in descending order
Set the array elements whose value is 13 to 0
Determine the number of odd integers in a vector
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!