Adding Second Callback to UIAxes Toolbar in App Designer
古いコメントを表示
I'm trying to find out how to add a second callback to the existing toolbar function(s) in App Designer so that one may, for example, hit the Restore View button and have the normal view restore callback as well as a custom function. I found some help here, but I wasn't able to get it to work properly. This was my attempt:
function callback2(app,~)
disp('The button was pushed.')
end
axtoolbar(app.UIAxes,{'export','pan','zoomin','zoomout','restoreview'}) %create toolbar for app.UIAxes
%@(e,d)matlab.graphics.controls.internal.resetHelper(d.Axes,true) %original function for ButtonPushedFcn
ax = app.UIAxes;
ax.Toolbar.Children(5).ButtonPushedFcn = cellfun(@(x)feval(x,app,ax),...
{@(app)matlab.graphics.controls.internal.resetHelper(ax,true),...
@(app)callback2(app)}); %change the restoreview callback to include the original function and my custom function
I don't think this is very difficult to do, but I was in a rush and ended up doing something else anyway. For future reference, this would be beneficial to know though. The version I'm using is 2020b.
3 件のコメント
What is d?
I can't get this to work but am interested.
app.UIAxes = uiaxes;
axtoolbar(app.UIAxes,{'export','pan','zoomin','zoomout','restoreview'}) %create toolbar for app.UIAxes
% NOTE: changed ax to app.UIAxes
app.UIAxes.Toolbar.Children(5).ButtonPushedFcn = cellfun(@(x)feval(x,app,d),...
{@(app,d)matlab.graphics.controls.internal.resetHelper(d.Axes,true),...
@(app)callback2(app)}); %change the restoreview callback to include the original function and my custom function
Error
Unrecognized function or variable 'd'.
Error in @(x)feval(x,app,d)
When I change it to,
app.UIAxes.Toolbar.Children(5).ButtonPushedFcn = cellfun(@(x)feval(x,app,[]),...
% ^^
Error
Dot indexing is not supported for variables of this type.
Error in @(app,d)matlab.graphics.controls.internal.resetHelper(d.Axes,true)
Error in @(x)feval(x,app,[])
Cameron B
2021 年 3 月 16 日
Adam Danz
2021 年 3 月 16 日
app.UIFig = uifigure();
app.UIAxes = uiaxes(app.UIFig);
axtoolbar(app.UIAxes,{'export','pan','zoomin','zoomout','restoreview'}) %create toolbar for app.UIAxes
%@(e,d)matlab.graphics.controls.internal.resetHelper(d.Axes,true) %original function for ButtonPushedFcn
ax = app.UIAxes;
ax.Toolbar.Children(5).ButtonPushedFcn = cellfun(@(x)feval(x,app,ax),...
{@(app,ax)matlab.graphics.controls.internal.resetHelper(ax,true),...
@(app,ax)callback2(app)}); %change the restoreview callback to include the original function and my custom function
function callback2(app,~)
disp('The button was pushed.')
end
Error
Error using myFcn>@(app)matlab.graphics.controls.internal.resetHelper(ax,true)
Too many input arguments.
Error in myFcn>@(x)feval(x,app,ax) (line 7)
ax.Toolbar.Children(5).ButtonPushedFcn = cellfun(@(x)feval(x,app,ax),...
When change the inputs to,
ax.Toolbar.Children(5).ButtonPushedFcn = cellfun(@(x)feval(x,ax,true),...
{@(app,tf)matlab.graphics.controls.internal.resetHelper(ax,tf),...
@(app)callback2(app)});
The error becomes,
Error using matlab.graphics.controls.internal.resetHelper
Too many output arguments.
Error in myFcn>@(app,tf)matlab.graphics.controls.internal.resetHelper(ax,tf) (line 8)
{@(app,tf)matlab.graphics.controls.internal.resetHelper(ax,tf),...
Error in myFcn>@(x)feval(x,app,true) (line 7)
ax.Toolbar.Children(5).ButtonPushedFcn = cellfun(@(x)feval(x,app,true),...
And since resetHelper is in an encrypted p-file, I don't know what the inputs and outputs should be.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Develop uifigure-Based Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!