How to multiply a matrix by certain numbers?
Show older comments
I want to multiply a matrix by a column vector in this way:
(4 2 3 8;7 9 1 5;6 4 8 3) * (4;8;2)
and then the result i want to get is:
(4*4 2*4 3*4 8*4;7*8 9*8 1*8 5*8;6*2 4*2 8*2 3*2)
3 Comments
Shubha Baravani
on 30 Jun 2019
If x=(1 2 3 4) And if y=(2 3 4 5) How can I multiply each sample of x by each sample of y so that I get the output as Z=(2 3 4 5 4 6 8 10 6 9 12 15 8 12 16 20)
madhan ravi
on 30 Jun 2019
xy = repmat(x,1,1,numel(x)) .* reshape(y,1,1,[]); % for version <=2016b bsxfun(@times,repmat(x,1,1,numel(x)) , reshape(y,1,1,[]))
Wanted = reshape(squeeze(xy).',1,[])
>> x = [1,2,3,4];
>> y = [2,3,4,5];
>> z = kron(x,y)
z =
2 3 4 5 4 6 8 10 6 9 12 15 8 12 16 20
Accepted Answer
More Answers (1)
>> X = [4 2 3 8;7 9 1 5;6 4 8 3];
>> Y = [4;8;2];
>> bsxfun(@times,X,Y)
ans =
16 8 12 32
56 72 8 40
12 8 16 6
Categories
Find more on MATLAB 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!