How to sum every elements that have the same frequency?

1 view (last 30 days)
Suppose I have 2 vectors of the same length.
A = [0.2 0.4 0.8 0.6 1.2 0.3];
B = [ 2 2 1 2 1 1];
The result that I want ---> A+B = [(0.2+0.4+0.6),(0.8+1.2+0.3)].
Please help. Thanks in advance.

Accepted Answer

KSSV
KSSV on 20 Aug 2020
A = [0.2 0.4 0.8 0.6 1.2 0.3];
B = [ 2 2 1 2 1 1];
iwant = [sum(A(B==2)), sum(A(B==1))]

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!