- Navigate to Model Configuration Parameters and select Simulation Target.
- In the Custom Code section, find the Defines option.
- Define your macro here, for instance: LEN=100.
- Once you have applied these configuration settings, you can easily use the macro within your 'C Function' block.
Declare C Array in C Function dependent on constant
27 次查看(过去 30 天)
显示 更早的评论
Dear Matlab-Team,
I would like to include some custom C code into my Simulink model using the C Caller / C function block. As I need some intermediate variables, I would like to declare a C array dependent on the size of the input "LEN", which is constant.
float data[LEN];
As C only allows direct values or macros, I cannot use the constant in the ports and parameters section. I would like to avoid to pre allocated temporarily needed arrays in Simulink and then feed as reference to my function. Also I need to avoid dynamic memory allocation like malloc.
Is there any option to declare a macro for example that can be then used in the C function?
Thanks for your support!
0 个评论
回答(1 个)
aditi bagora
about 3 hours 前
Hi Simon,
I understand that you want to define a macro to specify the array length for use in the 'C Function' block. Simulink offers a convenient way to achieve this through the 'Defines' section in the configuration panel. Please refer to the steps below to implement this approach:
Please refer to the following MathWorks documentation for more details on defining macros : https://www.mathworks.com/help/simulink/gui/defines.html
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!