Element Wise Multiplication Not Giving Expected Result
古いコメントを表示
Hi experts,
I am new to Matlab so would appreciate all your help.
I am trying to do element wise multiplication of two 3D matrices. One matrix (A) contains random integers having a size of 10x2x1,000,000; and the other one (B) contains 0 and 1 numbers having a size of 10x2x1024. All data is uint8 integer.
As a first thought, I took each slice of 10x2 in matrix A and perform element wise multiplication with each slice of 10x2 in matrix B. However, I could not get the expected results. The code is as below:
% A slice of A
A(:,:,n) = [3, 4;
2, 5;
4, 3;
3, 4;
1, 6;
5, 2;
3, 4;
4, 3;
4, 3;
6, 1];
% A slice of B
B(:,:,m) = [1, 0;
1, 0;
0, 1;
1, 0;
1, 0;
0, 1;
1, 0;
0, 1;
0, 1;
0, 1];
% Element wise multiplication
C = A.*B;
As I run this code, I got different result than what I expect it to be:
% Result from above code:
C = [3, 0;
2, 0;
0, 3;
3, 0;
0, 6;
0, 2;
0, 4;
4, 0;
0, 3;
0, 1];
% Expected result:
C = [3, 0;
2, 0;
0, 3;
3, 0;
1, 0;
0, 2;
3, 0;
0, 3;
0, 3;
0, 1];
Please help me explain what is wrong here.
Also, I have an extra question. If I were to take each slice of matrix A and perform element wise multiplication with all the slices in matrix B at one go, and repeat this computation for all the slices in matrix A, how can I do this in an efficient way?
Thank you for your help. Looking forward to receive all your suggestions.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!