Info

この質問は閉じられています。 編集または回答するには再度開いてください。

About passing the parameter

5 ビュー (過去 30 日間)
k38
k38 2017 年 4 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi, I would appreciate if someone answer me this question.
I am developing the GUI which calls one function called fun1.
Fun1 will get one of the value from uicontrol, say variable a.
But I have a another function called fun2.
I tried to use a in fun2 but I got the error, structure is like this
Func_main()
Uicontrol(...,callback,"fun1") Fun1() a = get.value End
Fun2() Disp(a); End
End
How can I pass the parameter from one function to another?
Sorry for so naive question but thanks for your help

回答 (1 件)

Jan
Jan 2017 年 4 月 5 日
編集済み: Jan 2017 年 4 月 5 日
You can store the value in the "handles" struct:
function Main
hFigure = figure;
uicontrol(..., 'Callback', @Callback1);
uicontrol(..., 'Callback', @Callback2);
handles.a = []; % Default value
guidata(hFigure, handles); % Store handles struct in the figure
end
function Callback1(hObject, EventData)
handles = guidata(hObject); % Get struct from figure
handles.a = get_value() % Insert value
guidata(hObject, handles); % Put struct back to figure
end
function Callback2(hObject, EventData)
handles = guidata(hObject); % Get struct from figure
disp(handles.a)
end
This is a frequently asked question, I esitmate 2 times per day. Search in the forum for "share data between callbacks".
  2 件のコメント
Joseph Cheng
Joseph Cheng 2017 年 4 月 5 日
Ah... I always forget that this works outside of GUIDE. (deleted my submission).
k38
k38 2017 年 4 月 5 日
Hi Jan, thank you very much for your answer, I was working on the project and I struggled with this but you really saved me!
Once again, thank you!!

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by