set uiaxes in matlab function as current figure to plot on
19 次查看(过去 30 天)
显示 更早的评论
Hi folks,
I had a question on how to plot on uiaxes from an m-file. This question got solved:
I wonder if there's a more elgant way to solve this problem by defining the axes at the beginning of the function and then continuously plot on it instead of defining the axes in every single plot command?! Something like:
Call of function:
myFunction(app.uiaxes)
Function:
function myFunction(uiAxes)
axes(uiAxes)
% plot 1
...
% plot 2
...
% plot x
It works fine the way it is right now, but what if I have an old function with lots of plot commands I want to include to a gui?
0 个评论
采纳的回答
J. Alex Lee
2020-10-8
I would argue that it makes more sense (more elegant) to require specifying the parent axes to plot. The way that you want may cut down on some letters, but to me is less elegant and more prone to problems and confusion.
I would take the advice of the comment in the other answer: ctrl+F to update your old code.
7 个评论
Mario Malic
2020-10-8
编辑:Mario Malic
2020-10-8
plot(ax,___) creates the line in the axes specified by ax instead of in the current axes (gca). The option ax can precede any of the input argument combinations in the previous syntaxes.
plot function without ax argument, plots into gca - that is of following types:
- An Axes object.
- A PolarAxes object.
- A GeographicAxes object.
- A standalone visualization
Maybe in one of the future versions they may think of including uiaxes to the list.
CurrentAxes property is useful, but then handle of the figure would have to be stored and "plotting" would actually be changing the Data properties (as mentioned above in Cris' answer), which includes rewriting the old function. Well, changing properties is probably faster than plotting. One can notice the same method used in optimisation plot functions.
You can extend the functionality of the old code, by doing the ctrl+f thing and include axes to plot to, in the old function. add a line on start of the code
ax = gca;
J. Alex Lee
2020-10-8
Mario's comment reminds me that while you can set the uifigure's CurrentAxes property, that will probably not help with directing plot commands to specific uiaxes - so really not sure what it's there for (I never looked it up)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!