How can I create a persistent structure variable that is initialized using external C-Code in Simulink 7.5 (R2010a)?

5 visualizaciones (últimos 30 días)
I would like to make a persistent Embedded MATLAB structure that is populated by an external C structure.
For example, I would like to use my custom function 'use_struct' to initialize an instance of a custom structure (MyStruct) to use the following values
my_instance.s1=42;
my_instance.s2=84;

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 7 de Sept. de 2010
The attached example demonstrates how you may externally initialize a persistent structure variable.
Note the following about the attached files:
1. The files "use_struct.h" and "use_struct.c" are included into the model through the following options:
use_struct.h
Configuration Parameters> Simulation Target> Custom Code> Include custom C code in generated> Header file> #include "use_struct.h"
use_struct.c
Configuration Parameters> Simulation Target> Custom Code> Include list of additional> Source files> use_struct.c
Check the option - Configuration Parameters> Real-Time Workshop> Custom Code> Use the same custom code settings as Simulation Target
2. In the Embedded MATLAB function block of TS_example.mdl, line 4 declares 'my_persistent_struct' as a persistent variable and then in lines 7 and 8 this persistent variable is first initialized to be a structure and then overwritten by a call to the custom C-code ('use_struct') that initializes this variable.
For more information, consult the documentation by executing the following at the MATLAB prompt:
doc struct

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2010a

Community Treasure Hunt

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

Start Hunting!

Translated by