Divide large size matrixes, multiply the small matrixes and sum the results together.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I divided two m x n matrixes A and B into several equal i x j matrices using mat2cell, respectively, and then I want to multiply the respective split matrixes and sum them together like
A11, … , A1j , ... Ai1, … , Aij are built from A, and
B11, … , B1j , ..., Bi1, … , Bij , are built from B,
What I want is
C = A11* B11 + … + Aij* Bij
Are there any commands in matlab can do this?
Many thanks!
4 commentaires
Andrei Bobrov
le 18 Mai 2019
What you want, Elements multiplication or matrix multiplication in any case your formula will give an error:
>> A = rand(32, 32 );
B = rand(32, 32 );
A11_77 = mat2cell (A, [ 2 2 2 2 2 2 4 2 2 2 2 2 2 4 ] , [ 2 2 2 2 2 2 4 2 2 2 2 2 2 4] );
B11_77 = mat2cell (B, [ 2 2 2 2 2 2 4 2 2 2 2 2 2 4 ] , [ 2 2 2 2 2 2 4 2 2 2 2 2 2 4] );
>> A11_77{6,7} * B11_77{6,7}
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows
in the second matrix. To perform elementwise multiplication, use '.*'.
>> A11_77{1,1} * B11_77{1,1} + A11_77{7,7} * B11_77{7,7}
Matrix dimensions must agree.
>>
Réponses (1)
Andrei Bobrov
le 18 Mai 2019
Modifié(e) : Andrei Bobrov
le 18 Mai 2019
C = sum(A.*B,'all')
for MATLAB < R2018b :
AB = A.*B;
C = sum(AB(:));
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!