Problem 44324. Rewrite setdiff to account for non-unique values
Setdiff(a,b) is a function that will remove all values of b from a. Sometimes, you need this function to do a little bit extra, though. Write a newer version of setdiff that will take into account numbers appearing multiple times in a. For example:
a=[8 7 6 5 4 3 2 1 1]; b=[1 3 4 5 6 7];
In this example, setdiff(a,b) would return [2 8], since only 2 and 8 are not included in a. However, there are two "1" values in a, and only one "1" in b, so new_setdiff should return [1 2 8]. Your output vector should be sorted from low to high.
You can assume that there are no Inf or NaN in either vector, and that no values will appear in b more times than will appear in a.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers28
Suggested Problems
-
Remove the small words from a list of words.
1497 Solvers
-
It dseon't mettar waht oedrr the lrettes in a wrod are.
1814 Solvers
-
Project Euler: Problem 9, Pythagorean numbers
1151 Solvers
-
Determine Whether an array is empty
775 Solvers
-
654 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!