Multiple one column of one matrix with all column of another matrix
2 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
the cyclist
on 1 Feb 2021
Edited: the cyclist
on 1 Feb 2021
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;
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!