Help! How to find mutual numbers in 2 different vectors and replace them with the start and end not in common?

I have this situation 2016 2059 43 2362 2450 88 2450 2474 25 2474 2684 36 3301 3332 31
I would like to find the mutual numbers in the 2 column, replace them and add the number in the column number 3. here is the output that i would like to get
2016 2059 43 2362 2684 149 3301 3332 31

2 Comments

I don't understand. Where are your two vectors? You just give us a list of numbers. The question in the title is not understandable. Could you please tell us more clearly what you want to do?
when i have in start date and in end date mutual value. i want to delete them and get the start value and the last value not in common. and the duration has to b added.Can you help me out?

Sign in to comment.

 Accepted Answer

a = [2016 2059 43
2362 2450 88
2450 2474 25
2474 2684 36
3301 3332 31];
b = reshape(a(:,1:2),[],1);
[b1,ii] = histc(b,unique(b));
a1 = reshape(b(ismember(ii,find(b1<2))),[],2);
i1 = zeros(size(a,1),1);
i1(ismember(a(:,1),a1(:,1))) = 1;
out = [a1,accumarray(cumsum(i1),a(:,3))];

2 Comments

what if the difference between the first column and the second one is 1 and or zero?

Sign in to comment.

More Answers (0)

Categories

Asked:

on 5 Jun 2014

Commented:

on 6 Jun 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!