필터 지우기
필터 지우기

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 CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by