Writing Workspace with M file
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Kaustubha Govind
2012-3-28
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 个评论
Kaustubha Govind
2012-3-30
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!