Writing Workspace with M file
Ältere Kommentare anzeigen
So, i'm working on a code-generation project, wich is intended to be used by people who aren't used to work with Matlab/Simulink.
When using signals/parameters in the project, these parameters/signals need to be ASAP2 defined, but i want to make this easier for the people who have to work with it by inserting blocks into my custom library of simulink, that will define the parameters/signals for them, while they define the parameters (datatype, storageclass, min/max values) in the block mask.
My question is, is there a way to let an M file (attached to the simulink block) write defining commands (name = ASAP2.Signal; etc) into the matlab workspace?
Antworten (1)
Kaustubha Govind
am 28 Mär. 2012
0 Stimmen
You can write your MATLAB code in Block Callback Functions. You can put it in LoadFcn if you want the commands to run only once at model load time, or in InitFcn if you want them to run every time the user updates (Ctrl+D) or runs (Ctrl+T) the model.
2 Kommentare
Kevin
am 29 Mär. 2012
Kaustubha Govind
am 30 Mär. 2012
Kevin: LoadFcn is run as soon as the model is loaded, regardless of whether you run simulation/code-generation or do nothing at all. AFAIK, the InitFcn is run every time the model is updated - this happens every time both before simulation and code-generation.
Did you want to create the variables *only* for code-generation, but never for simulation? If yes, you may use a slightly more advanced concept of a hook file. See http://www.mathworks.com/help/toolbox/rtw/ug/f10435.html
You can try writing your code in the 'entry' hook and see if that works.
Kategorien
Mehr zu Simulink Coder finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!