MATLAB: Identifying duplicates and deleting duplicates

diff()duplicates

v1 =[300 350 350 350 360 370 380 380 380 390 395 405 450 450 450 450 450 450 500 500 500 500 500 500]
v2 = [NaN 1 2 3 3 NaN 1 2 3 NaN 2 NaN 1 2 3 1 2 3 1 2 3 1 2 1 ]
I am trying to make a script which identifies data which is repeated in v1 and v2 (when they are combined) and then deletes the repeated data in both v1 and v2.
I've been looking at this problem for a long time, I really don't know where to start. I started of using a = find(diff(v1)==0) but that didn't get me anywhere. I'm very bad at explaining my problems, here is the desired output of the script(may help with understanding the problem):
v1 =[300 350 350 350 360 370 380 380 380 390 395 405 450 450 450 500 500 500]
v2 = [NaN 1 2 3 3 NaN 1 2 3 NaN 2 NaN 1 2 3 1 2 3 ]

Best Answer

Use unique( ,'rows')
v1 =[300 350 350 350 360 370 380 380 380 390 395 405 450 450 450 450 450 450 500 500 500 500 500 500]
v2 = [NaN 1 2 3 3 NaN 1 2 3 NaN 2 NaN 1 2 3 1 2 3 1 2 3 1 2 1 ]
v1_out =[300 350 350 350 360 370 380 380 380 390 395 405 450 450 450 500 500 500]
v2_out = [NaN 1 2 3 3 NaN 1 2 3 NaN 2 NaN 1 2 3 1 2 3 ]
out=unique([v1' v2'],'rows');
z1=transpose(out(:,1));
z2=transpose(out(:,2));
isequal(v1_out,z1)
isequalwithequalnans(v2_out,z2)
If v2 is cell array of strings, then NaN is not an issue.
v1=[1 1 1 11 12];
v2={'a','ab','a','b','a'};
str=[num2str(v1'),char(v2)];
[str,index]=unique(cellstr(str));
v1=v1(index)
v2=v2(index)