필터 지우기
필터 지우기

Undefined variable in workspace (GUI - Simulink)

조회 수: 2 (최근 30일)
Trick Verzosa
Trick Verzosa 2016년 8월 25일
Hi, I would like to ask for advise on an error encountered while making a GUI linked to a Simulink model.
I created a model that calculates some data and I placed ToWorkspace blocks in every end to transfer the results to the workspace and be used in the GUI script. In the script, at the pushbutton callback, I tried this code
function pushbutton1_Callback(hObject, eventdata, handles) %#ok
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set_param('samplemdl','SimulationCommand','start');
workspace = get_param('samplemdl', 'ModelWorkspace');
myValue = getVariable(workspace,'var1');
set(handles.edit1, 'string', myValue);
but when I run the simulation from the GUI, I get this error,
Error using samplegui>pushbutton1_Callback (line 151)
Undefined variable 'var1' in workspace ('samplemdl').
so, I tried this (even though hundreds of discussions suggest not to use this)
get_param('samplemdl', 'ModelWorkspace');
myValue = evalin('base','var1');
set(handles.edit1, 'string', myValue);
and the values from workspace is shown in the edit box. but when I changed some input values and run the simulation, the values in the edit boxes didn't change but on the model the values in the display blocks changed.
Please help, what is the correct way of doing this? Thanks.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by