Error Invalid or deleted object while creating a line
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I created a dot that is moving through the figure after this function bellow is called; I get an error invalid or deleted object after I close a figure. Also, I can't manage to figure out how to delete a customer dot after button is clicked again. I attached another function showing the button clicked called pushStart. Please help me!
function customerMoving(a)
customerVel = [ -1, 0];
customerPos = [90,45];
customer = line(customerPos(1), customerPos(2),'marker','.','markersize',50,'color',[.8 .6 .6]);
tic;
customerWaiting = false;
while toc < 20
if customerPos(1) < 42 && customerVel(1) == -1
customerVel(1) = 0;
customerVel(2) = 1;
end
if customerPos(2) > 71
customerVel(1) = -1;
customerVel(2) = 0;
end
if customerPos(1) < 34 && customerVel(1) == -1
customerVel(1) = 0;
customerVel(2) = -1;
end
if customerPos(2) < 18 && customerVel(2) == -1
customerVel(1) = 0;
customerVel(2) = 0;
customerWaiting = true;
pause(0.5);
end
if customerWaiting == true
if customerPos(1) < 34
customerVel(1) = -1;
customerVel(2) = 0;
end
if customerPos(1) < 28
customerVel(1) = 0;
customerVel(2) = 1;
end
if customerPos(2) > 26
customerVel(1) = -1;
customerVel(2) = 0;
end
if customerPos(1) < 22
customerVel(1) = 0;
customerVel(2) = 0;
end
end
customerPos = customerPos + customerVel;
if a == true
set(customer, 'XData',customerPos(1),'YData',customerPos(2));
else
set(customer, 'XData',0,'YData',0); % ???????????? NEED TO REMOVE ALL THE CUSTOMERS ?????????
end
pause(0.05);
end
end
function pushStart (hObject, event, handles)
global dayStart;
if dayStart == false
set(hObject, 'String', 'Close');
dayStart = true;
customerMoving(true);
else
set(hObject, 'String', 'Start Day');
dayStart = false;
customerMoving(false);
end
end
0 commentaires
Réponses (1)
Image Analyst
le 7 Déc 2019
When you create a line object and get the handle of the line graphic into "customer" if you want to "NEED TO REMOVE ALL THE CUSTOMERS" then delete the line handle with delete:
customer = line(customerPos(1), customerPos(2),'marker','.','markersize',50,'color',[.8 .6 .6]);
drawnow; % Force immediate update so we can see the line.
% More code....
% Delete the line from the graph:
delete(customer);
drawnow;
5 commentaires
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!