Multiple one column of one matrix with all column of another matrix

2 ビュー (過去 30 日間)
Yen Su
Yen Su 2021 年 2 月 1 日
コメント済み: Yen Su 2021 年 2 月 1 日
I have two array
array1=[0.5 0.7 0.9; 1.2 1.8 2.1;2.5 3.4 5.3; 3.1 7.1 2; 3 4 8; 9 4 7; 1 2 3; 4 3 9]
and
array2=[21 23 24 27; 21 87 45 33; 55 88 66 44; 33 21 34 55; 33 87 43 98;21 23 24 27;21 23 24 27;21 23 24 27]
I want to multiply each data of second column of array1 i.e (0.7 1.8 3.4 7.1 4 4 2 3) with all element of array2 column to column (i.e. 0.7x21 1.8x21 3.4x55 7.1x33 4x33 4x21 2x21 3x21 and so on). How can I do that? Any advice is appreciated.

採用された回答

the cyclist
the cyclist 2021 年 2 月 1 日
編集済み: the cyclist 2021 年 2 月 1 日
If you have a relatively up-to-date version of MATLAB (R2016b or later), with implicit expansion, then
output = array1(:,2).*array2;
will give the result you want.
If you have an older version, you'll need to do the expansion yourself, for example with
output = repmat(array1(:,2),1,size(array2,2)) .* array2;
  1 件のコメント
Yen Su
Yen Su 2021 年 2 月 1 日
For 2018b version first code works. Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by