Filter löschen
Filter löschen

Why do I get the error "Invalid or deleted object." for the following code?

6 Ansichten (letzte 30 Tage)
When I run the code for the first time, I get this error. However when I run it for a second time my code is able to run through to completion.
start = pi;
points = 250; % decrease to increase speed of marker
end_ = 0;
disc = pi/16;
theta = linspace(pi,0,points);
rho = sin(theta);
theta2 = linspace(0,pi,points);
rho2 = -sin(theta2);
p = polarscatter(theta(1),rho(1),'o','Filled','red');
for i = 0:15
interval = linspace(start+i*disc,end_+i*disc,points);
interval2 = linspace(end_+i*disc,start+i*disc,points);
polarplot(interval,rho)
hold on
for k = 2:length(interval)
p.XData = interval(k);
p.YData = rho(k);
drawnow
end
pause(0.1)
polarplot(interval2,rho2)
for k = 2:length(interval2)
p.XData = interval2(k);
p.YData = rho2(k);
drawnow
end
pause(0.1)
end
disp('Finished.')

Akzeptierte Antwort

Adam Danz
Adam Danz am 27 Jun. 2018
Bearbeitet: Adam Danz am 27 Jun. 2018
The reason you're getting the error is because you're updating p.XData where p is the output to polarscatter() however your call to polarplot() overwrites that axis so p is gone.
A solution is to grab the axis handle of polarscatter(), hold the axis, and pass the handle to your two calls to polarplot().
Grab the handle, hold the axis
p = polarscatter(theta(1),rho(1),'o','Filled','red');
ph = p.Parent; %axis handle
hold(ph, 'on')
Pass the handle to polarplot()
polarplot(ph,interval,rho)

Weitere Antworten (0)

Kategorien

Mehr zu Polar Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by