Assigning variables in model workspace from GUI in 2010b

2 次查看(过去 30 天)
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

采纳的回答

Anders
Anders 2011-3-10
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by