Divide large size matrixes, multiply the small matrixes and sum the results together.

3 visualizaciones (últimos 30 días)
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 comentarios
Andrei Bobrov
Andrei Bobrov el 18 de Mayo de 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.
>>
Tony Cheng
Tony Cheng el 18 de Mayo de 2019
Dear Andrei ,
Thanks so much for your reminding!
Yeah, the dimension must match for the matrix multiplication. Just above I used an unrigorous example to illustrate the problem, but what I want is dividing the two big matrixes into many small ones, then multypling the small ones, and finally get the summation of each multiplication.
I think your solution
C = sum(A.*B,'all')
must be right. However, A and B are not divided into small one. And in my case, the dimension of A and B are very very high, if A*B are computed directly, it takes a very very long time to finish. Also, we want to observe the multiplication of small matrixes and get the physical meanings inside the mathematical expressions.
Accounting these two reasons, we make a strategy that, first, we divide the two big matrixes into small ones, and then multiply the small ones, finally add the multiplications together.

Iniciar sesión para comentar.

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 18 de Mayo de 2019
Editada: Andrei Bobrov el 18 de Mayo de 2019
C = sum(A.*B,'all')
for MATLAB < R2018b :
AB = A.*B;
C = sum(AB(:));

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by