Size mismatch in Simulink for element wise multiplication
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Martin Rupp
am 17 Feb. 2022
Kommentiert: Martin Rupp
am 28 Feb. 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
0 Kommentare
Akzeptierte Antwort
Mark McBroom
am 26 Feb. 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;
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Additional Math and Discrete finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!