Error in callback function execution in App Designer when called programmatically
20 views (last 30 days)
Show older comments
Sreerup Banerjee
on 28 Jul 2020
Commented: Sreerup Banerjee
on 3 Aug 2020
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.
0 Comments
Accepted Answer
Adam Danz
on 28 Jul 2020
Edited: Adam Danz
on 3 Aug 2020
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.
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 Comments
Adam Danz
on 3 Aug 2020
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.
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!