Getting an error while trying to animate a plot

5 views (last 30 days)
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?

Accepted Answer

Simon Chan
Simon Chan on 22 Feb 2023
Use capital letter D
p.XData = x(1,k);
p.YData = y(1,k);
%..^

More Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!