필터 지우기
필터 지우기

How to multiply two matrices

조회 수: 3 (최근 30일)
Dineth Senevirathne
Dineth Senevirathne 2017년 5월 14일
답변: Andrei Bobrov 2017년 5월 14일
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