Filter löschen
Filter löschen

Assigning variables in model workspace from GUI in 2010b

2 Ansichten (letzte 30 Tage)
Anders
Anders am 8 Mär. 2011
Hi all,
I've previously been assigning workspace variables from a GUI in simulink using the following code in the initialization tab of an empty subsystem:
hws = get_param(bdroot, 'modelworkspace');
hws.assignin('someName', someVariable);
With MATLAB 2010b this is no longer possible since the workspace in locked during model compilation. So the question is, does anyone know of another way to do this in 2010b?
Thanks -- Anders

Akzeptierte Antwort

Anders
Anders am 10 Mär. 2011
Ok, I've found a solution that seems to work.
1. In the Model Explorer under Model Workspace, set data source to "MATLAB Code".
2. In the code box add something like:
hparam = find_system(get_param(bdroot, 'Handle'),...
'SearchDepth', 1, 'Name',...
'Name-Of-Parameter-Block');
VarName = eval(get(hparam, 'ParamName'));
3. In the Model Hierarchy of the Model Explorer, select your system, right-click and select properties.
4. Click the Callback tab and select InitFcn.
5. Add the following code:
hws = get_param(bdroot, 'modelworkspace');
hws.reload;
6. Close all dialogs and simulate a happy man/woman.
If you have a better solution please submit it.

Weitere Antworten (0)

Kategorien

Mehr zu Modeling finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by