Function working as a matlab script but not working when copied into a simulink block (Matlab Function)

조회 수: 3 (최근 30일)
I am trying to use the following code inside the Matlab Function Block of Simulink, its giving me size mismatch error while building the model. But when the same code is written as a matlab script and executed, it works perfectly. I suspect that the error arises because of how load function works for simulink. Can anyone provide some pointers on how to modify the code in order to avoid this mismatch in the behaviour of matlab and simulink?
data = coder.load("values.mat");
a = {data.w.l_0,data.w.l_1,data.w.l_2};
b = {data.g.l_0, data.g.l_1, data.g.l_2};
b = {data.s.l_0, data.s.l_1, data.s.l_2};
ctl = 0.0;
x = [0.3,0.03,0.03,0.03];
ctl = compute_output(x, a, b, c, 3);
  댓글 수: 2
Sandeep Mishra
Sandeep Mishra 2025년 1월 16일
Can you please provide the specific error message and the MATLAB release version you're using?
Additionally, can you share the "values.mat" file, so that it would help community understand and reproduce the issue.
ASHWIN
ASHWIN 2025년 1월 21일

Hi Sandeep, it is not possible to share the original .mat file. I will create a sharable version and attach it with the question. Thank you.

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

답변 (1개)

Githin George
Githin George 2025년 1월 21일
Hi Aswin,
I feel that we are missing some elements here, like the inputs and outputs of the MATLAB Function Block, the variable definition for “c”, the “compute_output” function etc.
But with the limited information provided I am able to see that the provided code is supported in MATLAB Function block. So, the issue may lie with the MAT file contents or additional context that we are missing here (Note that I am using a dummy “compute_output” function and dummy MAT files).
I am attaching my model and related code here. Please provide additional details so that I can try from my end in case you are still facing issues.
Note that I am doing only Simulation and not Code Generation.
  댓글 수: 2
ASHWIN
ASHWIN 2025년 1월 21일

Thank you for providing a detailed response. I will go through your implementation and try to see if that helps. Yes, I need the Code Generation feature, which may also be the source of the issue here.

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

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by