Element wise (.*) in Simulink for two matrices with different dimensions

2 views (last 30 days)
Let Anxm and Bnx1 be two matrices with different dimensions
On Matlab: element-wise multiplication ie. A.*B = a Cnxm Matrix with no errors.
Example:
[1 2 3; 4 5 6;] .* [1; 0] = [1 2 3; 0 0 0]
However on Simulink If I use the Product block set on element-wise multiplication on A and B I get mismatch widths or dimensions Error.
Note that If I used a Matlab function Block on Simulink that calls A.*B. I am able to get the result I need. but I am looking for a solution that does not use the matlab function Block. Please share any solution you might think of.
Thanks!

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 27 Feb 2023
Edited: Fangjun Jiang on 27 Feb 2023
a=[1 2 3; 4 5 6];
b=[1; 0];
a.*b
ans = 2×3
1 2 3 0 0 0
This is a change made in MATLAB in R2016b when implicit expansion is introduced. Prior to R2016b, it will cause a "size mismatch" error.
Simulink does not have similar change to make it be supported by its blocks, as far as R2022b.
To make a block diagram work, and with your existing data "b", you will have to expand it yourself through another block
c=ones(1,3);
a.*(b*c)
ans = 2×3
1 2 3 0 0 0

More Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!