How to share variables between two GUI callbacks

7 次查看(过去 30 天)
Hi,
I am new to GUI and I need help sharing data between two GUI callback functions.
What I want: I have two check boxes and the names of the check boxes are analaysis_1d and analysis_2d. When analysis_1d is selected I want a panel(uipanel6) to become visible. If analysis_1d is selected first and the user also selects analysis_2d, I want the panel(uipanel6) to become invisible. Or, if analysis_2d is selected first and then analysis_1d is selected after, I want the panel(uipanel6) to remain invisible.
Here is my code:
***********************************************************************************************
function analysis_1d_Callback(hObject, eventdata, handles)
val = get(hObject,'Value');
if val == 1
set(handles.uipanel6,'visible','on')
handles.metricdata.analysistype_1d = 1
else
set(handles.uipanel6,'visible','off')
set(handles.GMdir1_box,'value',0)
set(handles.GMdir2_box,'value',0)
end
guidata(hObject,handles)
function analysis_2d_Callback(hObject, eventdata, handles)
val = get(hObject,'Value')
if val == 1
handles.metricdata.analysistype_2d = 1
else
end
guidata(hObject,handles)
***********************************************************************************************
I am not sure what to do and I would appreciate any help.
Thank you.

回答(2 个)

Amir
Amir 2014-8-4
编辑:Amir 2014-8-27
I don't have access to Matlab now, but I hope this helps you: Look at "setappdata" and "getappdata" documents. for example in your analysis_1d function you can save a variable (for example: OneOfYourVariablesIn_analysis_1d) by using this: step 1:
setappdata(handles.analysis_1d,'YourNewVariableName',OneOfYourVariablesIn_analysis_1d);
% By using this code the variable OneOfYourVariablesIn_analysis_1d (which was accessible inside the analysis_1d will be stored in GUI's workspace which can be accessed in other functions.
Step 2: In order to get access to the value of variable YourNewVariableName in analysis_2d:
ReadValue= getappdata(handles.analysis_1d,'YourNewVariableName');
Also look at the following files which show how you can pass variables between two GUI callbacks: I hope this helps

Image Analyst
Image Analyst 2014-8-4

类别

Help CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by