Linkaxes function on UIAxes in Appdesigner are not supported, is there a way to manually link two axes in AppDesigner?
4 次查看(过去 30 天)
显示 更早的评论
What might be the best solution to link the X axis for two charts using appdesigner? I was trying to use:
linkaxes([app.UIAxes, app.UIAxes2],'x');
But I received the following error:
Error using linkaxes (line 61)
Functionality not supported with UIAxes. For more information, see Graphics Support in App Designer.
Are there any current workarounds to this functionality in Appdesigner?
2 个评论
Andrew Diamond
2019-12-30
The obvious workaround is ot set a listener on limit changes (xlim, ylim) so that when the limits of one axis changes your listener's callback will get triggered and then you can use that to set any other would-be linked axes.
However, I read somewhere that you can't depend on limit notifications (maybe just in app designer).
So, I used a timer. In my app designer code/class I have a variable MyTimer for my timer and one, LastXYLims, for to store the Last limits (I don't recall why I made thie public. I don't think it needs to be.)
properties (Access = public)
MyTimer
LastXYLims;
end
I set the timer up in my startup callback. The timer call back function, TimerFcn, takes two args (the timer and an event) but I want the callback to use the app's (object) axes so I used an anonymou TimerFcn that calls my MyTimerCallback with the app (and the other two args for completelness)
methods (Access = private)
% Code that executes after component creation
% create timer to call MyTimerCallback every half second. Not started though
function startupFcn(app)
app.MyTimer = timer('BusyMode','drop','Name','fred','ExecutionMode','fixedRate','Period',0.5,...
'TimerFcn',@(T,E) MyTimerCallback(app,T,E));
end
...
MyTimerCallback compares the x and y lims of my two would be linked axes (app.axFL and app axBF) and if one isn't the same than it has changed and so I set the other one equal to that and set the app.LastXYLims to the new limits.
methods (Access = private)
...
function MyTimerCallback(app,T,E)
axFLLims = get(app.axFL, {'xlim', 'ylim'});
axBFLims = get(app.axBF, {'xlim', 'ylim'});
if(~isequal(axFLLims, app.LastXYLims))
set(app.axBF, {'xlim', 'ylim'}, axFLLims);
app.LastXYLims=axFLLims;
elseif(~isequal(axBFLims, app.LastXYLims))
set(app.axFL, {'xlim', 'ylim'}, axBFLims);
app.LastXYLims=axBFLims;
end
end
...
I don't actually start the timer or initalize app.LastXYLims until I load the image into the axes
methods (Access = private)
function results = loadimages(app)
cla(app.axBF);
cla(app.axFL);
stop(app.MyTimer); % turn off linking (fine if timer not even started yet)
imagesc(app.axBF,app.BFImage);
imagesc(app.axFL,app.FLImage);
app.LastXYLims=get(app.axFL, {'xlim', 'ylim'});
start(app.MyTimer); % linked
...
回答(1 个)
Walter Roberson
2018-6-17
There does not appear to be any equivalent. There might possibly be a work-around involving listeners post-set on property changes. However, I suggest you have a look at https://blogs.mathworks.com/loren/2015/12/14/axes-limits-scream-louder-i-cant-hear-you/ for discussion of the difficulties involved even for traditional axes (and see the comments.)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!