Problem 73. Replace NaNs with the number that appears to its left in the row.
Solution Stats
Problem Comments
-
1 Comment
The problem does not limit the array to a single row. Add a few cases of multiple rows or define as single row.
Solution Comments
-
1 Comment
x = [1:10 NaN];
y_correct = [ 1:10 10];
assert(isequal(replace_nans(x),y_correct))
c =
1 2 3 4 5 6 7 8 9 10 NaN
Output argument "y" (and maybe others) not assigned during call to "replace_nans".
Error in Test4 (line 3)
assert(isequal(replace_nans(x),y_correct))
why wont this pass?
-
2 Comments
Not really a solution, more like a "white flag" regarding this direction.
hint: recursion
-
1 Comment
big size ...!
-
3 Comments
I just realized that you can cause inconvenience to some players by posting cody problems like "Hello Everyone!!!". I did create that cody problem just to say Hi to my fellow cody players. It was not intended to waste your time or cause inconvenience. My apologies for whoever deleted that problem.
I am sure it was deleted by mistake, there are plenty of similar Cody problems (think Chuck Norris, indian mathematicians, smartest matlab programmers, and a long etc...) Perhaps Ned can put it back up?
Thanks for the reply sir.
-
2 Comments
Strange...those assertions pass on my computer
For the second test it gives: [0 0 1 2 2 2 17 3 -4] instead of [0 1 2 2 2 17 3 -4 -4]
-
1 Comment
Nice, it is very intuitive that a solution with this function is possible but still hard to find.
-
2 Comments
It's like a lesson. logical indices don't have to be full size! And for will apparently loop through a vector! Thanks!
Bonus! Vector doesn't have to be monotonic!
Problem Recent Solvers2605
Suggested Problems
-
6724 Solvers
-
First non-zero element in each column
848 Solvers
-
Back to basics 20 - singleton dimensions
265 Solvers
-
378 Solvers
-
382 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!