Can I somehow use a variable from a pushbutton function to another pushbutton function

조회 수: 1 (최근 30일)
Xp_1=0;
Yp_1=0;
Xp_4=0;
Yp_4=Y_val;
Xp_3=X_val;
Yp_3=Y_val;
Xp_2=X_val;
Yp_2=0;
Xp=[Xp_1,Xp_2,Xp_3,Xp_4];
Yp=[Yp_1,Yp_2,Yp_3,Yp_4];
hold(app.UIAxes_10,"on");
plot(app.UIAxes_10,Xp,Yp);
[xi,yi]=getpts(app.UIAxes_10);
p = [xi yi];
I want to use [xi,yi] in another pushbutton function

채택된 답변

Richard Burnside
Richard Burnside 2023년 6월 23일
편집: Richard Burnside 2023년 6월 23일
Yes you can but you will have to store the data. A decent choice is the UserData field of the gui figure, root object or guidata.
At the time you create the gui figure you could place a tag:
hf = uifigure('HandleVisibility','on',...
'Name','Flight Data Analysis', ...
'Toolbar','none','MenuBar','none','Resize','off',...
'Color',[1 1 1],...
'Tag','MainFig');
and then within a button callback function find the object and assign or read data from the UserData field:
mf = findobj('Tag','MainFig');
data = mf.UserData;
Other places to store data are "guidata" or using the UserData field of the root object with "groot".

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by