Problem 76. De-dupe
Remove all the redundant elements in a vector, but keep the first occurrence of each value in its original location. So if
a = [5 3 6 4 7 7 3 5 9]
then
dedupe(a) = [5 3 6 4 7 9]
Solution Stats
Problem Comments
-
4 Comments
why I use ver.2012b can pass all the tests,but not succeded in cody?
[b,ia]=unique(a,'first');
b=sortrows([b;ia]',2)';
b=b(1,:);
solved in one line !
nice problem
Hi, bainhome:
Cody is based on the 'current' version of MATLAB, not R2012b. Many functions are unchanged, but a few have changed (modified, new, or removed), including "unique".
You must add the 'legacy' flag to the list of arguments to preserve the behaviour of the "unique" function from R2012b and prior releases — refer to the documentation (link posted by Jakub Galecki).
—DIV
if u know a specific function its too easy.
Solution Comments
Show commentsProblem Recent Solvers2958
Suggested Problems
-
Read a column of numbers and interpolate missing data
2255 Solvers
-
Given an unsigned integer x, find the largest y by rearranging the bits in x
1720 Solvers
-
Find the largest value in the 3D matrix
1483 Solvers
-
Get the length of a given vector
10334 Solvers
-
Basics: 'Find the eigenvalues of given matrix
408 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!