For Loop Only Working with Specified Value Range "''index exceeds number of array elements""

1 Ansicht (letzte 30 Tage)
In the code shown below the for loop only works when the value of 's' is equal to one, this is annoying though as the range over which i want to run the for loop is really between approximatly 20 and 100, not 1 and 100. when I change 's' to be 20 say, it says ''index exceeds number of array elements"
clc, clear, close all
g= 9.81;%Gravity
mc= 13;%Craft mass
ml= 50;%Load mass
m= mc+ml;%Total load
ws= 10.9118;%Wingspan
A= 16.1653;%Wing area
w= m*g;%Weight
u= 25.83;%Flight speed
rho= 1.225;%Density
c= A/ws;%Chord length
N= 1;%For loop step
%Calculating Cl as speed increases
s= 20;
F= 100;
u= (s:N:F);
for n= s:N:F
CL(n)=w/(0.5*rho*c*u(n)^2);
end
figure()
plot(u,CL,'linewidth', 2)
xlabel('Operating Speed (m/s)')
ylabel('Lift Coefficient')

Akzeptierte Antwort

DGM
DGM am 22 Nov. 2021
Don't need the loop
g= 9.81;%Gravity
mc= 13;%Craft mass
ml= 50;%Load mass
m= mc+ml;%Total load
ws= 10.9118;%Wingspan
A= 16.1653;%Wing area
w= m*g;%Weight
u= 25.83;%Flight speed
rho= 1.225;%Density
c= A/ws;%Chord length
N= 1;%For loop step
%Calculating Cl as speed increases
s= 20;
F= 100;
u= s:N:F;
CL = w./(0.5*rho*c*u.^2);
plot(u,CL,'linewidth', 2)
xlabel('Operating Speed (m/s)')
ylabel('Lift Coefficient')

Weitere Antworten (0)

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by