Problem 60186. Remove Unique Elements
Given a list of integers, we want to keep only the non-unique elements in this list. To do this, we need to remove all the unique elements (elements that appear only once). The resulting list, denoted by C, must not change the order of the original list. Complete the function dupe(L) which returns the new list C.
Example:
- If L=[1,2,3,1,3] then C=[1,3,1,3]
- If L=[1,2,3,4,5] then C=[]
- If L=[5,5,5] then C=[5,5,5]
- If L=[10,9,10,10,9,8] then C=[10,9,10,10,9]
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Christian Schröder
on 5 May 2024
Could I persuade you to use isempty() when the correct result is empty, rather than comparing to [] (which is 0-by-0 and will not match a 1-by-0 array)?
minnolina
on 13 May 2024
? You've convinced me! I'll start using isempty() when the correct result is empty. Thanks for the tip!
Christian Schröder
on 14 May 2024
Thank you!
Dyuman Joshi
on 11 Jun 2024
This feels like quite a deceptive question. Looks easy but gets tricky to work it out for larger inputs.
Solution Comments
Show commentsProblem Recent Solvers11
Suggested Problems
-
Find the numeric mean of the prime numbers in a matrix.
8895 Solvers
-
Determine if a Given Number is a Triangle Number
376 Solvers
-
Back to basics 21 - Matrix replicating
1504 Solvers
-
Create logical matrix with a specific row and column sums
301 Solvers
-
Generate a random matrix A of (1,-1)
313 Solvers
More from this Author53
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!