How to multiply two matrices

3 次查看(过去 30 天)
Dineth Senevirathne
Hello i have two matrices.
  1. a 2749*1 matrix
  2. a 500*1 matrix
i want to multiply above matrices like this
  • first 500 rows of 1st matrix with 2nd matrix and store the value
  • jump 250 rows (now we are in 750th row)
  • then 2nd 500 rows (from 750th row to 1250th row) of 1st matrix with 2nd matrix and store the valuelikewise.you have to get the transpose of the first matrix to match the dimension to multiply. (1*500 and 500*1)
  1 个评论
John D'Errico
John D'Errico 2017-5-14
So I am forced to wonder why two people are asking virtually the same question. Sounds like homework to me.

请先登录,再进行评论。

回答(3 个)

Michael Saniuk
Michael Saniuk 2017-5-14
>> A = rand(2749,1);
>> B = rand(500,1);
>> C = A(1:500,1).*B;
>> D = A(751:1250,1).*B;

Star Strider
Star Strider 2017-5-14
What output do you want from your vector multiplication?
Try this:
A = randi(9, 1, 2500); % Create Data
B = randi(9, 500, 1); % Create Data
for k1 = 1:2
Result(:,k1) = A(1, (1:500)+(k1-1)*250).' .* B;
end
This does element-wise multiplication, producing a vector in ‘Result’. If you want a single value (dot-product), change ‘.*’ to ‘*’.

Andrei Bobrov
Andrei Bobrov 2017-5-14
A - vector 2749 x 1
B - vector 500 x 1
A1 = reshape(A(1:2*749),749,[]);
out = A1(1:500,:).' * B; % dot-product
out = A1(1:500,:) .* B; % element-wise MATLAB >=R2016b
out = bsxfun(@times,A1(1:500,:),B); % element-wise MATLAB >=R2016b

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by