Within a GUI created with App Designer can I call a function associated with one button inside the code for a different button?

I have the code below associated with the EXIT button of my GUI. Can I call this function inside the code for a different button? If so, how?
% Button pushed function: EXITButton
function EXIT(app, event)
if isfile( '_TEMP_.jpg' )
delete( '_TEMP_.jpg' )
end
if isfile( '_PREV_.jpg' )
delete( '_PREV_.jpg' )
end
if isfile( '_CURR_.jpg' )
delete( '_CURR_.jpg' )
end
close all
app.delete
end

 採用された回答

Kevin Holly
Kevin Holly 2022 年 10 月 18 日
編集済み: Kevin Holly 2022 年 10 月 18 日
When you create a new function, you can just call that function.
function differentButton(app, event)
EXIT(app)
end

5 件のコメント

If I use
Preset2Button( app )
App Designer tells me to use
app.Preset2Button( app )
and gives me a FIX button to make this change. If I make the change and then run my app, I get the following error message ("destroyer3" is the name of my app):
Unable to use a value of type destroyer3 as an index.
Error in destroyer3/GO (line 452)
app.Preset2Button( app )
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
is Preset2Button defined as a property value? Is it a UIComponent and not the function?
Is PrivateButtonPushedFcn or Preset2ButtonPushedFcn your function? If so, you should call that.
Preset2ButtonPushedFcn(app)
See the app attached for an example.
This worked. Thanks! I still have a question about how to get answers to questions like this about App Designer on my own. Is there a manual or comprehensive tutorial?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

リリース

R2022b

質問済み:

2022 年 10 月 18 日

コメント済み:

2022 年 10 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by