How to multiply two matrices
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello i have two matrices.
- a 2749*1 matrix
- 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 commentaire
John D'Errico
le 14 Mai 2017
So I am forced to wonder why two people are asking virtually the same question. Sounds like homework to me.
Réponses (3)
Michael Saniuk
le 14 Mai 2017
>> A = rand(2749,1);
>> B = rand(500,1);
>> C = A(1:500,1).*B;
>> D = A(751:1250,1).*B;
0 commentaires
Star Strider
le 14 Mai 2017
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 ‘*’.
0 commentaires
Andrei Bobrov
le 14 Mai 2017
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
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!