set uiaxes in matlab function as current figure to plot on

조회 수: 32 (최근 30일)
Dominik Müller
Dominik Müller 2020년 10월 8일
편집: Mario Malic 2020년 10월 8일
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?

채택된 답변

J. Alex Lee
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
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
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 CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by