Linkaxes function on UIAxes in Appdesigner are not supported, is there a way to manually link two axes in AppDesigner?

4 views (last 30 days)
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 Comments
Andrew Diamond
Andrew Diamond on 30 Dec 2019
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
...
Adam Danz
Adam Danz on 15 Apr 2021
Edited: Adam Danz on 15 Apr 2021
Update: linkaxes became supported with uiaxes in app designer either in r2020a or r2020b. I currenlty don't have access to r2020a but it's supported in r2020b and not supported in r2019b and I couldn't find relevant info in the release notes.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 17 Jun 2018
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.)

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!