MATLAB Answers

How to share variables between two GUI callbacks

12 views (last 30 days)
Carlos
Carlos on 4 Aug 2014
Edited: Amir on 27 Aug 2014
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.
  1 Comment
Ben11
Ben11 on 4 Aug 2014
What about the answers to your other question. Did any of the ideas suggested work for you?

Sign in to comment.

Answers (2)

Amir
Amir on 4 Aug 2014
Edited: Amir on 27 Aug 2014
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

Community Treasure Hunt

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

Start Hunting!