How can I create a persistent structure variable that is initialized using external C-Code in Simulink 7.5 (R2010a)?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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;
Risposta accettata
MathWorks Support Team
il 7 Set 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
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Simulink Coder in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!