Effacer les filtres
Effacer les filtres

Getting an error while trying to animate a plot

25 vues (au cours des 30 derniers jours)
Pallov Anand
Pallov Anand le 22 Fév 2023
Commenté : Pallov Anand le 22 Fév 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?

Réponse acceptée

Simon Chan
Simon Chan le 22 Fév 2023
Use capital letter D
p.XData = x(1,k);
p.YData = y(1,k);
%..^

Plus de réponses (0)

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by