How do I multiply vector elements in the following fashion???

Suppose I have A=[18 44 20 55] & B=[4 6]
Now I want C=[18*4 44*4 20*6 55*6]
i.e I want to multiply first element of B with first pair of elements in A
and second element of B with second pair of A and so on...

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 2 日
編集済み: Azzi Abdelmalek 2016 年 4 月 2 日

0 投票

A=[18 44 20 55]
B=[4 6]
out=reshape(bsxfun(@times,A',B),1,[])

3 件のコメント

Maruti Patil
Maruti Patil 2016 年 4 月 2 日
Actually I want answer to be Out=[18*4 44*4 20*6 55*6] i.e total
number of elements should be same as in A i.e 4 in this case
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 2 日
Then you have to reshape A
reshape(bsxfun(@times,reshape(A,2,2),B),1,[])
Maruti Patil
Maruti Patil 2016 年 4 月 2 日
Thank you

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by