简体   繁体   English

如何使用 Embedded Coder 将 Matlab LUT 导出到 C 代码?

[英]How to export Matlab LUT to C code using Embedded Coder?

I have data from Simulink (Lookup tables generated from non-linear functions) 100x100 double array and my goal is to export it in the most efficient way from Matlab to C code so that I can implement it on a microcontroller and perform the interpolation.我有来自 Simulink(非线性函数生成的查找表)100x100 双数组的数据,我的目标是以最有效的方式将其从 Matlab 导出到 C 代码,以便我可以在微控制器上实现它并执行插值。

I am interested in exporting the variables as opposed to functions which then I can easily use in the C files.我有兴趣导出变量而不是函数,然后我可以轻松地在 C 文件中使用它们。

I have tried code generation with Matlab Coder however it is designed for converting Matlab function to C function which is not what I need. I have tried code generation with Matlab Coder however it is designed for converting Matlab function to C function which is not what I need.

Unfortunately, I haven't worked with Matlab for 10 years, so my answer may not be the best one.不幸的是,我已经有 10 年没有使用 Matlab 了,所以我的答案可能不是最好的。

As Jabberwocky already wrote, you might write a simple script that writes something like int foo[] = {... to a file.正如 Jabberwocky 已经写的那样,您可以编写一个简单的脚本,将类似int foo[] = {...的内容写入文件。

Simulink models have a property named PostCodeGenCommand . Simulink 模型有一个名为PostCodeGenCommand的属性。 This property contains a list of Matlab commands and/or scripts to be executed after RTW code generation.此属性包含要在 RTW 代码生成后执行的 Matlab 命令和/或脚本的列表。 And the value (the list of commands) is saved in the Simulink (.mdl) file.值(命令列表)保存在 Simulink (.mdl) 文件中。 Details are described on the MathWorks web site . MathWorks web 站点上描述了详细信息。

If you write the script writing the int foo[] =... in Matlab (.m) instead of C, you may add this script to the PostCodeGenCommand property so it is executed everytime you generate code.如果您在 Matlab (.m) 而不是 C 中编写int foo[] =...的脚本,则可以将此脚本添加到PostCodeGenCommand属性,以便在每次生成代码时执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM