필터 지우기
필터 지우기

Index error while doing animation

조회 수: 3 (최근 30일)
Robert Fields
Robert Fields 2022년 4월 23일
댓글: Robert Fields 2022년 4월 23일
I need help fixing this error to create the final adjustments of my animation for a school projuct error code is as follows and here is code as well.
Index exceeds the number of array elements (77).
Error in Group_Porject (line 67)
plot(t2(k2),z3(k2),'x')
clear all;
close all;
clc
x0 = [0,0];
tspan = [0,6000];
[t1,x] = ode45(@f1,tspan,x0);
[t2,y] = ode45(@f2,tspan,x0);
z = x(:,1)/1609.34;
figure(1)
plot(t1,z)
ylabel('Horizontal Distance (mi)')
z2 = x(:,2)*1.94384;
figure(2)
plot(t1,z2)
ylabel('Horizontal Velocity (kts)')
z3 = y(:,1)*3.28084;
figure(3)
plot(t2,z3)
ylabel('Vertical Distance ft)')
z4 = y(:,2)*3.28084;
figure(4)
plot(t2,z4)
ylabel('Vertical Velocity (ft/s)')
for k = 1:length(x)
figure (5)
plot(t1(k),z(k), 'x')
hold on
plot(t1(k),z2(k),'x')
plot(t1(1:k),z(1:k))
hold on
plot(t1(1:k),z2(1:k))
axis ([0 6000 0 140])
legend ('Horizontal Distance', 'Horizontal Velocity')
pause(0.05)
if k ~= length(t1)
clf
end
end
for k2 = 1:length(x)
figure (6)
plot(t2(k2),z3(k2),'x')
hold on
plot(t2(k2),z4(k2),'x')
hold on
plot(t2(1:k2),z3(1:k2))
hold on
plot(t2(1:k2),z4(1:k2))
axis ([0 60000 0 2000000])
pause(0.05)
if k2 ~= length(t2)
clf
end
end
function dxdt = f1(t,x)
T = 1030;
if (x(1)>90*1609.34)
T=0;
end
m = 1000;
cd = 0.27;
dxdt(1,1) = x(2);
dxdt(2,1) = T/m-cd/m*x(2)^2;
end
function dydt = f2(t,y)
m = 1000;
W = m*9.81;
L = W + 50*exp(-.005*t);
dydt(1,1) = y(2);
dydt(2,1) = L/m-W/m;
end
  댓글 수: 2
Star Strider
Star Strider 2022년 4월 23일
The ‘z’ vectors are all defined by ‘y’ so incrementing by the length of ‘y’ will not throw the error:
for k2 = 1:length(y)
figure (6)
plot(t2(k2),z3(k2),'x')
hold on
plot(t2(k2),z4(k2),'x')
hold on
plot(t2(1:k2),z3(1:k2))
hold on
plot(t2(1:k2),z4(1:k2))
axis ([0 60000 0 2000000])
pause(0.05)
if k2 ~= length(t2)
clf
end
end
The plot seems to not be consistent with the others.
.
Robert Fields
Robert Fields 2022년 4월 23일
Awesome thank you with that I got it figured out.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by