How to share variables between two GUI callbacks
조회 수: 3 (최근 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
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!