Borrar filtros
Borrar filtros

Assigning variables in model workspace from GUI in 2010b

2 visualizaciones (últimos 30 días)
Anders
Anders el 8 de Mzo. de 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

Respuesta aceptada

Anders
Anders el 10 de Mzo. de 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.

Más respuestas (0)

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by