(App Designer) How to link axes of UIAxes components to enable user to zoom all plots together in AppDesigner 2018b?
조회 수: 20 (최근 30일)
이전 댓글 표시
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.
My software version is 2018b. How do I workaround this issue? What is the logic of using listeners for my purpose?
댓글 수: 0
채택된 답변
Kevin Chng
2018년 12월 4일
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.
추가 답변 (2개)
Weidong Xu
2019년 11월 30일
편집: Weidong Xu
2019년 11월 30일
Another workaround, which was suggested by app designer's migration report, is to
"Call the axes, polaraxes, or geoaxes function to create the axes first. Create the desired plot, and then call the linkprop function."
For example, you can create app.UIAxes in the StartupFcn by calling
app.UIAxes = axes(app.FigureUI);
(rather than app.UIAxes = uiaxes(app.FigureUI), which was called by app designer constructor by default). Then linkprop will work for app.UIAxes.
댓글 수: 0
Eddy Fry
2022년 6월 16일
I managed to get this working in 2022a by adding linkaxes code to startupFcn as follows:
evStr = 'linkaxes([app.UIAxes_1';
for i = 2:nAxes
evStr = [evStr,',app.UIAxes_',num2str(i)];
end
evStr = [evStr,'],''xy'');'];
eval(evStr);
There is probably a better way than using eval(), but this is OK for me right now as I'm not compiling the code.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!