如何在生成的代码中加入C函数调用

7 ビュー (過去 30 日間)
Vico Wu
Vico Wu 2022 年 4 月 13 日
回答済み: mark li 2022 年 4 月 13 日
我想要搭建一个simulink模型,我查了资料可以通过matlab function 调用的形式加入c代码,但是我的c代码是API的.a文件关联的文件很多,我想在生成的代码中 某个位置直接包含我想要调用的函数体,不用去解析API的库文件,不用去考虑他的实现 只要在相应位置有这段代码就可以
例如 api 中有一个函数叫 in_cfg(uint16 a,uin16 b,uint16 c),我只要 生成的代码的某个逻辑位置有 in_cfg(a,b,c);

回答 (1 件)

mark li
mark li 2022 年 4 月 13 日
你好!你可以开配置中添加API,具体是model setting (Ctrl+E)->Simulation Target, 填写.c和.h。
代码生成也许要嵌进去,model setting (Ctrl+E)->Code Genaration->Custom Code填写.c和.h。
之后你用statflow调用即可,stateflow需要选择C语言
可以参考这个例子https://ww2.mathworks.cn/help/stateflow/ug/calling-c-functions-in-actions.html?searchHighlight=stateflow%20call%20c%20function&s_tid=srchtitle_stateflow%20call%20c%20function_3

カテゴリ

Help Center および File Exchange代码生成 についてさらに検索

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!