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 Center および File ExchangeInteractive 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