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.

 采纳的回答

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))]

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by