MATLAB Answers

App Designer 2020a: synchronizing UIAxes

9 views (last 30 days)
Waldemar on 29 Oct 2020
Commented: Adam Danz on 30 Jul 2021
Hi folx,
I'm programming an viewar for physiological data. My collegues wants to change zoom on x leaving y unchanged or vice versa. They also want to have a synchronized zoom on X (time) axis. I try to implement this, but it does not work. Of course I could program everything from scratch like in previous versions of matlab (with guide) but it would be nice to do this by extending the toolbar. But I got no hints how to do this.
Waldemar on 29 Jul 2021
This kind of interactivity is XXXXX (censored). For data display you want to have a synchronous zoom/pan on all axes simultaneously, or just x synchronized and y separate for each channel is needed. I dunno why in designer this functionality is not available. So, yes, you have to do it almost from scratch.
I already wrote the zoom functions for app-designer, now I'm working on pan. You must use button down/up functions and scrollwheel events (I use scroll wheel of the mouse for zoom).
It is a real pain in gluteus maximus

Sign in to comment.

Answers (1)

Adam Danz
Adam Danz on 30 Jul 2021
Edited: Adam Danz on 30 Jul 2021
You specified using Matlab R2020A which prevents you from using the new LimitsChangedFcn available in R2021a and onward which would simplify the solution.
The solution below deactivates panning and zooming interactivity for the y-axis and removes the pan and zoom tools from the toolbar. You can add tools as needed (see documentation). It then applies linkprop to yoke the two x-axes so that when the axis limits are changes in one axis, the other axis is updated.
% Create demo uifigure with 2 uiaxes
app.UIFigure = uifigure('Position', [500 200 700 400]);
app.UIAxes1 = uiaxes(app.UIFigure,'Position',[10 30 320 300]);
app.UIAxes2 = uiaxes(app.UIFigure,'Position',[340 30 320 300]);
% Limit toolbar to eliminate zoom and panning
tools = {'export','restoreview'};
% Deactivate zoom and panning interactions for the y-axis
zoomObj = zoomInteraction('Dimensions','x');
panObj = panInteraction('Dimensions','x');
app.UIAxes1.Interactions = [zoomObj, panObj];
app.UIAxes2.Interactions = [zoomObj, panObj];
% Plot some data, set axis limits, etc...
x = rand(1,100)*10-5;
y = rand(1,100)*20-10;
plot(app.UIAxes1, x, y, 'o')
plot(app.UIAxes2, x, y, 'o')
grid(app.UIAxes1, 'on')
grid(app.UIAxes2, 'on')
% Yoke the two axes' x-axis limits
app.UIAxes1.UserData.linkprop = linkprop([app.UIAxes1, app.UIAxes2], {'xlim'});
Adam Danz
Adam Danz on 30 Jul 2021
You could replace the uiaxes with regular axes.
App designer receives lots of enhancements with each release so you should consider updating to the current release of possible.
Also try using
linkaxes([app.UIAxes1, app.UIAxes2], 'x')
instead of linkprop but I had trouble with it so that may not work either.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by