Size mismatch in Simulink for element wise multiplication

4 vues (au cours des 30 derniers jours)
Martin Rupp
Martin Rupp le 17 Fév 2022
Commenté : Martin Rupp le 28 Fév 2022
Hello,
I have the following Matlab function in a Simulink model:
function [x_fro,m_fro] = fcn(x_mag,m_mag)
m_sup = [0; 0; 1] * ones(1,size(x_mag(1,:),2));
x_fro = x_mag - 2 * times(dot(x_mag,m_sup),m_sup);
m_fro = 2 * times(dot(m_sup,m_mag),m_sup) - m_mag;
In this case x_mag and m_mag are 3x2 Matrices(basically multiple vectors stacked for whom I want to do the same action). So from the dot product the result is a 1x2 Vector which should be element-wise multiplied with m_sup. This works in Matlab comand line perfectly fine. But in Simulink I get:
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
Size mismatch (size [1 x 2] ~= size [3 x 2]). Function 'CreateImage_fro' (#118.112.141), line 5, column 21: "times(dot(x_mag,m_sup),m_sup)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Size mismatch (size [1 x 2] ~= size [3 x 2]). Function 'CreateImage_fro' (#118.155.184), line 6, column 13: "times(dot(m_sup,m_mag),m_sup)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
I have tried with .* and with times but both result in the same error. I don't see where my error is. Could someone point out what I am doing wrong?
As information this is done in Matlab 2019b.
Best Regards
Martin

Réponse acceptée

Mark McBroom
Mark McBroom le 26 Fév 2022
the problem is that the sizes of the matrices to the times() function are not the same. dot(x_mag,m_sup) is 1x2 while m_sup is 3x2. ,For simulation, MATLAB will implicitly expand if possible, but for code generation sizes must be the same.
function [x_fro,m_fro] = fcn(x_mag,m_mag)
m_sup = [0; 0; 1] * ones(1,size(x_mag(1,:),2));
t_dot = dot(x_mag,m_sup);
t_dot = repmat(t_dot,3,1);
x_fro = x_mag - 2 * times(t_dot,m_sup);
t_dot = dot(m_sup,m_mag);
t_dot = repmat(t_dot,3,1);
m_fro = 2 * times(t_dot,m_sup) - m_mag;
  1 commentaire
Martin Rupp
Martin Rupp le 28 Fév 2022
Thank you, I figured out a similar way to work around this.
Kind regards,
Martin

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by