필터 지우기
필터 지우기

Size mismatch in Simulink for element wise multiplication

조회 수: 5 (최근 30일)
Martin Rupp
Martin Rupp 2022년 2월 17일
댓글: Martin Rupp 2022년 2월 28일
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;
  댓글 수: 1
Martin Rupp
Martin Rupp 2022년 2월 28일
Thank you, I figured out a similar way to work around this.
Kind regards,
Martin

댓글을 달려면 로그인하십시오.

추가 답변 (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