MATLAB: (App Designer) How to link axes of UIAxes components to enable user to zoom all plots together in AppDesigner 2018b

appdesignerlinkaxeslinkpropuiaxes

I am building an app where I have three plots in a single tab. What I want to do is showing user the specific zoomed area in the plots synchronized. To do that, I tried to use linkprop/linkaxes function but unfortunately it is not supported with UIAxes.
I have found this answer but I have no experience with listeners.
My software version is 2018b. How do I workaround this issue? What is the logic of using listeners for my purpose?

Best Answer

Hi Deniz,
As per knowledge, I don't how to do link them simultaneously. However, we may play small trick.
I have attached small sample hereby (.m file, since .mlapp is not accepted here, I copy the code and paste in .m file)
Idea : Enable Zoom for both axes in startup function, then use keypress callback function to reset another axes when one of the axes changes due to zoom
[However, from method above, user have to pressing one of the keyboard button when zooming the plot]
Step 1: Create Variables to store original XLim of both axes
properties (Access = private)
a % Description
b
end
Step 2 : Enable zoom for the both axes in startup function
zoom(app.UIAxes,'on')
zoom(app.UIAxes2,'on')
Step 3: Record the Xlim of axes after plotting them. In my attached, i do it in startup function
plot(app.UIAxes,[0 1],[0 1]);
plot(app.UIAxes2,[0 0.2 1],[0 0.9 1]);
app.a = app.UIAxes.Xlim;
app.b = app.UIAxes2.Xlim;
Step 4 :Use keyPress function to detect the changes of one axes, then it will change the xlimit and ylimit for another axes.
function UIFigureKeyPress(app, event)
key = event.Key;
if app.UIAxes.XLim ~= app.a
app.UIAxes2.XLim = app.UIAxes.XLim;
app.UIAxes2.YLim = app.UIAxes.YLim;
elseif app.UIAxes2.XLim ~=app.b
app.UIAxes.XLim = app.UIAxes2.XLim;
app.UIAxes.YLim = app.UIAxes2.YLim;
end
end
You may try to run my .m script to get the idea, when you wana zoom it and enable another axes to have same x&y limit, you must press one of the button in the keyboard.
I hope my workaround solution help you.