Write a function to get unique elements of a vector faster than unique()! Input will be a vector (of integers or floating point numbers) of any size. The order of the returned vector is unimportant.
Example: Input: x = [1 1 2 2 3 3]; Output: [1 2 3];
Input: x = [0.1 3.1 2.1 2.0 3.1]; Output: [0.1 3.1 2.1 2.0]; % or any order
Solution Stats
Problem Comments
7 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers31
Suggested Problems
-
501 Solvers
-
Project Euler: Problem 9, Pythagorean numbers
1385 Solvers
-
115 Solvers
-
Calculate the derivative of a polynomial
238 Solvers
-
564 Solvers
More from this Author7
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
I'm sure some smarter person will find a faster method!
My solution passed on the third try; there's definitely some CPU timing mismatch going on!
Agreed, some of my solutions passed only part of the time.
Hi, just wondering whether someone could help me out here. I was expanding the testset, and I was trying x = [1:10 2:11] but I got an error "Error: Dimensions of matrices being concatenated are not consistent." I then tried x = [1 2 3 4], and x = 1:4; but got the same error. On my version of MATLAB all these statements work perfectly and I believe they are basic MATLAB syntax. x = [1; 2; 3; 4] worked fine however. In the end I had to transpose the matrices.
Jeremy
it even cannot pass on my own computer, but....
Jeremy, please increase the size of the third case. Performance tests are not made with small samples (unless they are run several times)...because many other factors may affect the time (alternating processes, server overload, memory usage, etc). A regular CPU is always multi-tasking.
About your problem with arrays, try adding a comma between lists.