Reputation: 13
Say we want to concatenate two matrices a=[2 3 6] , b=[0 9 3 2 8 2] but we don't want any repetitive elements in the concatenated matrix. in other words we want c to be c=[2 3 6 0 9 8] Is there a built-in function that does that for us?
Upvotes: 1
Views: 40
Reputation: 259
% You could use the union function to accomplish this
a = [2 3 6]; % array a
b = [0 9 3 2 8 2]; % array b
% Use the union function to concatenate a and b. It lists an item that appears in either array once.
c = union(a,b, 'stable'); % adding 'stable' keeps your current order
Upvotes: 4