필터 지우기
필터 지우기

stupid question / pass Variables in a GUI

조회 수: 2 (최근 30일)
Max Müller
Max Müller 2014년 7월 28일
답변: Michael Haderlein 2014년 7월 28일
hey folks, two simple questions :D
function GetData_Callback(hObject, eventdata, handles)
x = str3num(get(handles.editbox1,'String'))
function UseData_Callback(hObject, eventdata, handles)
y = x +1
disp(y)
How can I pass x form the 1st Button to the 2nd Button ?

채택된 답변

Michael Haderlein
Michael Haderlein 2014년 7월 28일
Do you necessarily need to create x in the GetData_Callback? Why not just in the UseData_Callback? If you really need it this way, just initialize the variable x in the main function (before the callbacks start). Then the variable will be valid in the entire file (in all subfunctions).

추가 답변 (1개)

Ben11
Ben11 2014년 7월 28일
You can use the handles structure of your GUI to store variables.
eg:
function GetData_Callback(hObject, eventdata, handles)
handles.x = str3num(get(handles.editbox1,'String')) % store in handles structure
guidata(handles,hObject) % update structure
function UseData_Callback(hObject, eventdata, handles)
y = handles.x +1
disp(y)
That should work :)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by