Getting an error while trying to animate a plot
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pallov Anand
am 22 Feb. 2023
Kommentiert: Pallov Anand
am 22 Feb. 2023
I have a simple code. I am trying to animate the plot with my code like this:
clc
clear all
close all
t_span = 120;
dt = 0.01;
t = 0:dt:t_span;
%% constants
u1 = 2;
u2 = 0.2;
h0 = 2;
kh = 2;
x(1) = 5;
y(1) = 5;
psi(1) = 0;
h(1) = 0;
for n = 1:length(t)
u3(n) = - kh * (h(n)-h0);
x(n+1) = x(n) + dt * (u1 * cos(psi(n)));
y(n+1) = y(n) + dt * (u1 * sin(psi(n)));
psi(n+1) = psi(n) + dt * (u2);
h(n+1) = h(n) + dt * (u3(n));
end
figure(1)
p = plot(x(1), y(1), 'o','MarkerFaceColor','red','MarkerSize',3.5);
hold on
for k = 1:length(t)
title(['Time = ',num2str(k*dt)])
p.Xdata = x(k);
p.Ydata = y(k);
drawnow
pause(0.003)
end
In this, I am getting this error while plotting:
Unrecognized property 'Xdata' for class 'matlab.graphics.chart.primitive.Line'.
Error in stand_off (line 38)
p.Xdata = x(k);
Can anyone plz help me in resolving this?
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Animation 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!