Error Invalid or deleted object while creating a line

1 vue (au cours des 30 derniers jours)
Paulius Kazemekaitis
Paulius Kazemekaitis le 6 Déc 2019
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

Réponses (1)

Image Analyst
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
Paulius Kazemekaitis
Paulius Kazemekaitis le 8 Déc 2019
Would you mind checking it if Ill send you all the files?
Paulius Kazemekaitis
Paulius Kazemekaitis le 8 Déc 2019
Basically what happens is that I am doing tic; while toc < 20...
so when I am trying to delete it, I have to wait till it counts 20s. How can I make it so it will happen straight away after I click it?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by