フィルターのクリア

Getting an error while trying to animate a plot

5 ビュー (過去 30 日間)
Pallov Anand
Pallov Anand 2023 年 2 月 22 日
コメント済み: Pallov Anand 2023 年 2 月 22 日
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?

採用された回答

Simon Chan
Simon Chan 2023 年 2 月 22 日
Use capital letter D
p.XData = x(1,k);
p.YData = y(1,k);
%..^

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by