Size mismatch in Simulink for element wise multiplication
조회 수: 5 (최근 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
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Event Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!