I have a cell containing a number of arrays of numbers.
I need to find the duplicates (if any), and remove the shortest array, containing any duplicates.
Example: In c = {[1 2 3] [4 5 6] [1 7 8 9]} the number one is duplicate, and hence the cell should be c = {[4 5 6] [1 7 8 9]}, since [1 2 3] is the shortest array.
The size of the cell and the arrays varies.
This can be done using the union function, which does a set wise union on 2 vectors:
c = {[1 2 3] [4 5 6] [1 7 8 9]}
remove=[];
for k=1:length(c)
for l=k+1:length(c)
if length(union(c{k},c{l}))<length(c{k})+length(c{l})
if length(c{k})<=length(c{l})
remove=[remove;k];
else
remove=[remove;l];
end
end
end
end
for k=1:length(remove)
c(remove)=[];
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With