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

2 vues (au cours des 30 derniers jours)
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!

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 27 Fév 2023
Modifié(e) : Fangjun Jiang le 27 Fév 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

Plus de réponses (0)

Catégories

En savoir plus sur Event Functions dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by