Azzera filtri
Azzera filtri

Assigning variables in model workspace from GUI in 2010b

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Anders
Anders il 10 Mar 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.

Più risposte (0)

Categorie

Scopri di più su Modeling 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!

Translated by