How to have elementwise multiplication expand in two dimensions?

1 ビュー (過去 30 日間)
AlexRD
AlexRD 2022 年 6 月 24 日
コメント済み: AlexRD 2022 年 6 月 25 日
So I'm trying to optimize my code, and one aspect where it could really improve is to change one for loop to a SIMD instruction.
In short, I have two variables: A (16 x 16 x 3 x 100) and B(16 x 16 x 3 x 7)
What I want to do is to get an elementwise multiplication that expands to both the 100 and 7 dimensions, concatenating and returning a variable of size C (16 x 16 x 3 x 700).
If i do A .* B(:, :, :, 1) it automatically expands to the 100, but then i'd need a 7 iteration for loop concatenating along B.
How do i do this without a for loop?
Thanks!

採用された回答

Matt J
Matt J 2022 年 6 月 24 日
編集済み: Matt J 2022 年 6 月 24 日
C=A.*reshape(B,[16,16,3,1,7]);
C=reshape(C,[16,16,3,700]);
  1 件のコメント
AlexRD
AlexRD 2022 年 6 月 25 日
Thanks, that does it!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by