Problem 42671. unique with nan
input
x = [2 NaN 3 5 NaN; 1 NaN 4 9 NaN; 8 -2 7 6 -2; 7 4 8 5 4];
output
y_correct = [2 NaN 3 5; 1 NaN 4 9; 8 -2 7 6; 7 4 8 5];
Solution Stats
Problem Comments
-
6 Comments
First test case is invalid. Please fix it.
I have fixed it. Also rescored your score. Your solution is now correct.
A more complete description of what we're supposed to achieve would be useful. What are we supposed to do if a row has less elements than the others after applying unique? Pad it with zero as your second test seem to imply?
The objective of the problem is to find unique columns in the matrix, performing like unique(A,'columns','stable'), but treating NaN as equal numbers.
The explanation of Peng is correct. I inspired from the function of "isequalwithequalnans". You cannot use to test the equality of two arrays which contain nan values with the function of "isequal". The purpose is to write a function something like "uniquewithequalnans"
As standard unique does not operate on columns I didn't even realise that the example had two identical columns. I saw the problem as just remove the unique elements in each row which could potentially result in rows of different length. Hence my initial question.
Solution Comments
Show commentsProblem Recent Solvers36
Suggested Problems
-
Back to basics 21 - Matrix replicating
1531 Solvers
-
I've got the power! (Inspired by Project Euler problem 29)
120 Solvers
-
509 Solvers
-
Area of an equilateral triangle
6191 Solvers
-
ベクトル [1 2 3 4 5 6 7 8 9 10] の作成
549 Solvers
More from this Author92
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!