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

16 vues (au cours des 30 derniers jours)
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 commentaires
Andrew Diamond
Andrew Diamond le 30 Déc 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 le 15 Avr 2021
Modifié(e) : Adam Danz le 15 Avr 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.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 17 Juin 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.)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by