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

조회 수: 3 (최근 30일)
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
Andrei Bobrov
Andrei Bobrov 2019년 5월 18일
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 2019년 5월 18일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2019년 5월 18일
편집: Andrei Bobrov 2019년 5월 18일
C = sum(A.*B,'all')
for MATLAB < R2018b :
AB = A.*B;
C = sum(AB(:));

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by