How to share variables between two GUI callbacks

3 ビュー (過去 30 日間)
Carlos
Carlos 2014 年 8 月 4 日
編集済み: Amir 2014 年 8 月 27 日
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 件のコメント
Ben11
Ben11 2014 年 8 月 4 日
What about the answers to your other question. Did any of the ideas suggested work for 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 Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by