how can I change the current axes in a GUI?

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.
Greetings
Volker

댓글 수: 3

WCJHunter
WCJHunter 2019년 3월 22일
set(handles.figure,'CurrentAxes',handles.axes)
Qingyu
Qingyu 2019년 5월 14일
WCJHunter's answer works great! Thank you!
Rik
Rik 2022년 6월 13일
Comment posted as flag by Xb wang:
This ansewer is very useful.I spend servral days to find tha ways.Tank you !

댓글을 달려면 로그인하십시오.

 채택된 답변

Paulo Silva
Paulo Silva 2011년 2월 2일

10 개 추천

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.

댓글 수: 8

Volker
Volker 2011년 2월 2일
It works and I’ve got fun, thanks a lot for such a fast help!!!
Volker
Walter Roberson
Walter Roberson 2011년 2월 2일
Better yet would be to use
line(handles.axes2, ....)
without needing to activate the axes at all.
Richard Crozier
Richard Crozier 2013년 1월 9일
There is no such syntax
line(handles.axes2, ....)
This is the problem.
I'm trying to solve a nearly identical problem. However, what I'm seeing is that Matlab (2012b) seems to "forget" the current axes specification whenever that axes is in a GUIDE figure. Therefore, the following:
axes(handles.axes1)
plot([0 1],[0 1])
does not result in a line from (0,0) to to (1,1) in axes1 of the GUIDE figure, but rather it creates a new figure and plots the line in that new figure. Its strange, because the axes(handles.axes1) definitely sets the focus to the GUIDE figure first, so that part is working, but as soon as I try try to execute any command that applies to the current axes (e.g. plot, or even just "gca"), it creates a new figure and axes, i.e.:
> handles.axes1
ans = 215.0176
> axes(handles.axes1)
> gca
ans = 285.0266
with a new figure (with handle 285.0266) created.
Peter
Peter 2013년 1월 16일
Actually I just solved my issue... In the GUIDE layout figure window, one needs to select "Tools --> GUI Options --> Command-line accessibility" and change it to "On". The default setting was "Callback", and although the behavior I was getting was occurring inside callbacks, it didn't seem to work. Now it does.
Konstantinos
Konstantinos 2013년 9월 1일
Thanks Paulo, that worked great! Have been trying for a couple of days to solve that
Ryan
Ryan 2014년 8월 23일
Thanks Peters, the setting in GUIDE were my issue
Corne van Zyl
Corne van Zyl 2019년 4월 22일
Thank you for this!

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

thomeou
thomeou 2013년 6월 20일

0 개 추천

Thanks for the post I wasted one and a half day with this same problem
Chris Rorden
Chris Rorden 2013년 7월 22일

0 개 추천

Thanks, I also wasted a lot of time on this.
Itziar Uzqueda
Itziar Uzqueda 2017년 2월 23일

0 개 추천

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();
handles.x=1:20;
handles.h=animatedline('Marker','o','LineWidth',1,'Color','k');
for i=1:(length(handles.x))
handles.distancia(i)=fscanf(s,'%d');
addpoints(handles.h,i,handles.distancia(i));
drawnow;
end
cerrrar_puerto(s);
I want it to be plotted in my Matlab GUI.
Thanks, Itziar

댓글 수: 2

You should start a new question rather than post this as an answer.
You aren't specifying any axes though.
doc animatedline
In common with most plotting functions this includes a syntax that allows you to specify the axes handle as the first argument. Use it!
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

댓글을 달려면 로그인하십시오.

nadji hadroug
nadji hadroug 2018년 2월 19일

0 개 추천

You can see this example : x = 1000*rand(40,1); y = rand(40,1); scatter(x,y) xtickangle(45) ytickangle(90)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

질문:

2011년 2월 2일

댓글:

Rik
2022년 6월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by