MATLAB Answers

Error Invalid or deleted object while creating a line

1 ビュー (過去 30 日間)
Paulius Kazemekaitis
Paulius Kazemekaitis 2019 年 12 月 6 日
Commented: Paulius Kazemekaitis 2019 年 12 月 8 日
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 件のコメント

サインイン to comment.

件の回答 (1)

Image Analyst
Image Analyst 2019 年 12 月 7 日
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 件のコメント

表示 2 件の古いコメント
Paulius Kazemekaitis
Paulius Kazemekaitis 2019 年 12 月 8 日
I tried as a global variable in the pushStart function, still no luck... :(
Paulius Kazemekaitis
Paulius Kazemekaitis 2019 年 12 月 8 日
Would you mind checking it if Ill send you all the files?
Paulius Kazemekaitis
Paulius Kazemekaitis 2019 年 12 月 8 日
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?

サインイン to comment.

サインイン してこの質問に回答します。

製品


リリース

R2018a

Translated by