Error in callback function execution in App Designer when called programmatically

14 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Adam Danz
Adam Danz el 28 de Jul. de 2020
Editada: Adam Danz el 3 de Ag. de 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.
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 comentarios
Adam Danz
Adam Danz el 3 de Ag. de 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.
Sreerup Banerjee
Sreerup Banerjee el 3 de Ag. de 2020
Yeah. At the end, it solved the problem. Learnt a new thing as well. I am happy. :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by