필터 지우기
필터 지우기

Assigning variables in model workspace from GUI in 2010b

조회 수: 2 (최근 30일)
Anders
Anders 2011년 3월 8일
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