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

2 次查看(过去 30 天)
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by