Generate code of function that uses simulink

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

回答 (1 件)

Prasanth
Prasanth 2020 年 11 月 24 日

0 投票

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.
In this case, you should use Simulink Coder to generate C/C++ code from a Simulink model. The following documentation page helps you get started with Simulink Coder.
Hope this helps.

カテゴリ

ヘルプ センター および File ExchangeSimulink Coder についてさらに検索

質問済み:

2014 年 5 月 8 日

回答済み:

2020 年 11 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by