필터 지우기
필터 지우기

Error in callback function execution in App Designer when called programmatically

조회 수: 20 (최근 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 CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by