Error in callback function execution in App Designer when called programmatically

19 ビュー (過去 30 日間)
I am in the process of writing a code for an app in App Designer (rather re-writting an old code to bypass the javaframe issue). As I cannot find any drag and drop option for toobar in App Designer, I have added it programmatically using uitoolbar and added togglebuttons in the toolbar. Now I want to have an access of the properties of the app inside the callback function of the togglebutton. I have used {@myfunction, app} to pass the variable. I can print app from inside the function (to check the effectiveness, I have kept only app and return inside), but at the same time getting this error:
Unrecognized function or variable 'app'.
Error while evaluating Surface ButtonDownFcn.
Any help in this regard will be appreciated.

採用された回答

Adam Danz
Adam Danz 2020 年 7 月 28 日
編集済み: Adam Danz 2020 年 8 月 3 日
As of r2020a, the typical ToolBar is not (yet?) supported for UIFigures (eg, apps) but the property exists which usually means that support is coming soon.
This is how you would turn on the toolbar for UIFigures from your StartupFcn, if/when it becomes supported.
app.UIFigure.ToolBar = 'Figure'; % or 'auto'
% This will result in an error in the current release, r2020a.
So you're stuck with your current method for now. Alternatively, consider using a uimenu.
Set up the tool bar from with your StartupFcn function [how to add a startupFcn].
The first input to your startupFcn is the app variable which can be passed to your toobar callback functions.
% Example
function startupFcn(app)
tb = uitoolbar(app.UIFigure);
pt = uipushtool(tb);
pt.ClickedCallback = {@myfunc,app};
end
Then set up the callback function. In r2020a, an error occurs when the callback function is defined within app designer code, even if the callback function is public. So, the callback function must be defined in an external m-file until this problem is fixed. Update: Alternatively, seeSreerup Banerjee's comment below describing how the callback function can be hosted by the app.
function myfunc(scr, event, app)
% do stuff
end
  17 件のコメント
Adam Danz
Adam Danz 2020 年 8 月 3 日
Thanks for following up. Nesting the callback function within the startupFcn in that way makes sense. I don't think I've ever used a nested function in AppDesigner; I didn't even know that was supported.
Sreerup Banerjee
Sreerup Banerjee 2020 年 8 月 3 日
Yeah. At the end, it solved the problem. Learnt a new thing as well. I am happy. :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by