Divide large size matrixes, multiply the small matrixes and sum the results together.
2 ビュー (過去 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
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.
>>
回答 (1 件)
Andrei Bobrov
2019 年 5 月 18 日
編集済み: Andrei Bobrov
2019 年 5 月 18 日
C = sum(A.*B,'all')
for MATLAB < R2018b :
AB = A.*B;
C = sum(AB(:));
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!