How to calculate sum of all the possible combinations of two vector elements

4 ビュー (過去 30 日間)
Davoud
Davoud 2019 年 2 月 18 日
コメント済み: Ethan Duckworth 2024 年 2 月 24 日
I have two vectors A and B with different lengths. The B vector always have 4 elements. How can I obtain the vector C containing sum of all the possible combinations of elements of B vector with A.
For example B= [1 2 3 4] and A= [0.1 0.2 0.3 0.4 0.5 0.6]
Then C= [1.1 1.2 1.3 1.4 1.5 1.6 2.1 2.2 2.3 2.4 2.5 2.6 3.1 3.2 3.3 3.4 3.5 3.6 4.1 4.2 4.3 4.4 4.5 4.6]
Thank you
  2 件のコメント
Jon Wieser
Jon Wieser 2019 年 2 月 18 日
C=[B+A(:)]';
C=reshape(C,1,numel(C));
Davoud
Davoud 2019 年 2 月 19 日
It seems it doesn't work for my case of A=[0.0000 + 0.0000i -0.2689+0.6342i 0.2689+0.6342i 0.0000+1.2685i] and B=[0.0000+0.0000i 0.1404 + 0.5011i -0.1404+0.5011i 0.0000+1.0021i]. In each iteration B is otained from a matrix as B=D(:,i).

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 2 月 19 日
log(kron(exp(B),exp(A)))

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 2 月 18 日
C=reshape((A+B.')',[],1)'
  7 件のコメント
Andrei Bobrov
Andrei Bobrov 2019 年 2 月 20 日
+1
madhan ravi
madhan ravi 2019 年 2 月 21 日
@Andrei Bobrov: Thank you!

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by