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

arraycolumnMATLABmatrixmultiplicationmultiply

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.7×21 1.8×21 3.4×55 7.1×33 4×33 4×21 2×21 3×21 and so on). How can I do that? Any advice is appreciated.

Best Answer

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;