(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!