Size mismatch in Simulink for element wise multiplication

4 次查看(过去 30 天)
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

采纳的回答

Mark McBroom
Mark McBroom 2022-2-26
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by