Why won't Matlab plot anything?

조회 수: 1 (최근 30일)
Akram Khandash
Akram Khandash 2022년 9월 25일
댓글: Akram Khandash 2022년 9월 26일
clear all
close all
% given values %
m = 80; %kg the mass of the sprinter%
F_x= 400; %N%
L = 100; %m the lenght of the race%
p = 1.293; %kg/m^3 the density of the air%
A = 0.45; %m^2 the cross-sectional area%
Cd = 1.2; %the drag force%
w = 0; %air velocity
time = 10;
dt = 0.1;
n = round(time/dt);
D = zeros(n,1);
a = zeros(n,1);
v = zeros(n,1);
x = zeros(n,1);
t = zeros(n,1);
a(1)= F_x/m;
v(1)=0;
x(1)=0;
D(1)=0;
t(1)=0;
for i = 1:n-1
a(i+1) = (F_x - D(i))/m;
v(i+1) = v(i) + a(i)*dt;
D(i+1) = 0.5*p*Cd*A*(v(i)-w)^2;
x(i+1) = x(i)+ v(i)*dt + 0.5*a(i)*dt^2;
t(i+1) = t(i) + dt;
if x(i+1)>=100
return
end
end
f1 = plot(t,x);
f2 = plot(t,v);
f3 = plot(t,a);
This is my code.
plot dose not show up. I hope to get help fixing it

채택된 답변

Dyuman Joshi
Dyuman Joshi 2022년 9월 25일
Use break instead of return. As when you use return, any code after it won't be executed
"Be careful when you use return within conditional blocks, such as if or switch, or within loop control statements, such as for or while. When MATLAB reaches a return statement, it does not just exit the loop; it exits the script or function and returns control to the invoking program or command prompt."
m = 80; %kg the mass of the sprinter%
F_x= 400; %N%
L = 100; %m the lenght of the race%
p = 1.293; %kg/m^3 the density of the air%
A = 0.45; %m^2 the cross-sectional area%
Cd = 1.2; %the drag force%
w = 0; %air velocity
time = 10;
dt = 0.1;
n = round(time/dt);
D = zeros(n,1);
a = zeros(n,1);
v = zeros(n,1);
x = zeros(n,1);
t = zeros(n,1);
a(1)= F_x/m;
v(1)=0;
x(1)=0;
D(1)=0;
t(1)=0;
for i = 1:n-1
a(i+1) = (F_x - D(i))/m;
v(i+1) = v(i) + a(i)*dt;
D(i+1) = 0.5*p*Cd*A*(v(i)-w)^2;
x(i+1) = x(i)+ v(i)*dt + 0.5*a(i)*dt^2;
t(i+1) = t(i) + dt;
if x(i+1)>=100
break
end
end
f1 = plot(t,x);
f2 = plot(t,v);
f3 = plot(t,a);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by