Why do I get an error: "Invalid or deleted object"
Show older comments
I'm running the following simulation in MatLab:
for i=1:length(t)
addpoints(curve1,posX(i),posY(i)); %trajectory in inertial frame
ball1 = viscircles([posX(i) posY(i)],r,'LineWidth',4,'Color','black');
framex=arrow([0 0],[R*cos(Theta(i)) R*sin(Theta(i))]);
framey=arrow([0 0],[-R*sin(Theta(i)) R*cos(Theta(i))]);
addpoints(curve2,X(i,1),X(i,2)); %trajectory in rotating frame
ball2 = viscircles([X(i,1) X(i,2)],r,'LineWidth',4,'Color','black');
if (posX(i))^2+(posY(i))^2 >= R^2
delete(ball1);delete(ball2);
break;
end
drawnow;
pause(0.001);
delete(ball1);delete(ball2);delete(framex);delete(framey);
if ishghandle(curve1) == 0
break;
end
end
I tried to download the "arrow" function so I can be able to plot and update reference frames in my simulation. When the simulation runs to completion, everything is fine. However if I close the figure before the loop is completed, I get the error "Invalid or deleted object". The error points to the line where I call
delete(ball1);delete(ball2);delete(framex);delete(framey);
So I pretty much know for a fact that this error arises from me deleting this arrow call in the loop, somehow it's deleting it before I close the figure, so it gives an error saying there's nothing to delete? I don't know why. I've been using the line function before just fine, but arrow gives an error. How come?
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!