Problem with axes and animatedline

3 次查看(过去 30 天)
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. Although i have tried to define axes in here, i haven't been able to fix the error that appears 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
Thanks, Itziar

回答(1 个)

Adam
Adam 2017-2-23
编辑:Adam 2017-2-23
The problem here is not with the animated line plotting it is what you post at the top - that your axes no longer exist. That is why it creates a new axes when you don't specify one and why it throws an error when you do.
Judging by the name of your axes I assume they are axes defined in GUIDE? If so I'm not sure how you would end up deleting the axes. You should search through your code for any instruction that involves handles.axes1 and check that you are not explicitly deleting the axes. Axes in a GUIDE GUI have the same life time as the GUI itself unless you explicitly delete them.
I notice though also that your callback does not include a
guidata( hObject, handles )
call so any changes you make to the handles structure there will be lost after the callback. That in itself is not the cause of this particular problem, but it is a hint that you might have done something incorrect with the handles structure previously also.
  1 个评论
Itziar Uzqueda
Itziar Uzqueda 2017-2-23
Hi!
I have just solved it, it was a problem in the abrir_puerto() function because I had a 'close all' there so the mainwindow closes and there are no axes anymore.
Thanks for your answer.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by