Generate code of function that uses simulink

1 view (last 30 days)
Jonas Vervoort
Jonas Vervoort 2014年5月8日
Answered: Prasanth on 24 Nov 2020
Hi,
I would like to generate a C/C++ function from a matlab function that uses the sim command. Because the sim command is used in a function I had to change the 'SrcWorkspace' to current to be able to use the "FromWorkspace" input block in Simulink.
So my function for example...
function[result] = doSomthing (param1)
param2=2;
param3=3;
t=0.01;% sampletime
t_Final = 10;% stop time
options = simset('SrcWorkspace','current');
sim卡('Model',[],options);
result = resultX;% resultX comes from the simulink model
end
The problem that I have now is that the '%#codegen' gives warnings on the "unused" variabes param1,param2,... that are only used in the simulink model. Is there a solution to this problem? How can I generate C/C++ code for a matlab function that uses simulink.
Thanks in advance, Kind regards, Jonas

Answers (1)

Prasanth
Prasanth on 24 Nov 2020
Hi Jonas,
The workflow you are using, i.e., generating C/C++ code for a MATLAB function that calls 'sim' function to simulate a model is not a supported one.
I believe that you are looking how to generate C/C++ code for a Simulink model.
在这种情况下,您应该使用仿真软件编码器gen万博1manbetxerate C/C++ code from a Simulink model. The following documentation page helps you get started with Simulink Coder.
Hope this helps.

Community Treasure Hunt

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

Start Hunting!