how can I change the current axes in a GUI?

489 views (last 30 days)
Volker on 2 Feb 2011
Commented: Qingyu on 14 May 2019
Hi, how can I change the current axes in a GUI? I try to use the line function, but I don’t know how to activate the right axes for plotting in the wanted figure. I guess, there should be a simple solution, but I can’t find.
Qingyu on 14 May 2019
WCJHunter's answer works great! Thank you!

Sign in to comment.

Accepted Answer

Paulo Silva
Paulo Silva on 2 Feb 2011
Here's one example:
axes(handles.axes2); %set the current axes to axes2
axes(h) makes existing axes h the current axes and brings the figure containing it into focus. It also makes h the first axes listed in the figure's Children property and sets the figure's CurrentAxes property to h. The current axes is the target for functions that draw image, line, patch, rectangle, surface, and text graphics objects.

Sign in to comment.

More Answers (4)

thomeou on 20 Jun 2013
Thanks for the post I wasted one and a half day with this same problem

Chris Rorden
Chris Rorden on 22 Jul 2013
Thanks, I also wasted a lot of time on this.

Itziar Uzqueda
Itziar Uzqueda on 23 Feb 2017
Hi! My problem is that when I try to plot an animatedline into axis1, instead of plotting there, another window is opened. also, when I try to use axes(handles.axes1) it says:
ans =
handle to deleted Axes
Mi code is here:
function Medir_Callback(hObject, eventdata, handles)
s = abrir_puerto();
for i=1:(length(handles.x))
I want it to be plotted in my Matlab GUI.
Thanks, Itziar
Itziar Uzqueda
Itziar Uzqueda on 23 Feb 2017
oh, sorry i didn't notice, i'm new in this kind of matters.
The probelm is that if i specify axes in animatedlines like this it comes to the error below.
handles.h=animatedline('Marker','o','LineWidth',1,'Color','k','Parent', handles.axes1);
Error using animatedline While setting property 'Parent' of class 'AnimatedLine': Cannot set property to a deleted object

Sign in to comment.

nadji hadroug
nadji hadroug on 19 Feb 2018
You can see this example : x = 1000*rand(40,1); y = rand(40,1); scatter(x,y) xtickangle(45) ytickangle(90)


Community Treasure Hunt

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

Start Hunting!