How to sum every elements that have the same frequency?

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

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)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Tags

Asked:

on 20 Aug 2020

Commented:

on 20 Aug 2020

Community Treasure Hunt

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

Start Hunting!