Writing Workspace with M file
이전 댓글 표시
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?
답변 (1개)
Kaustubha Govind
2012년 3월 28일
0 개 추천
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
Kevin
2012년 3월 29일
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.
카테고리
도움말 센터 및 File Exchange에서 Simulink Coder에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!