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

1 view (last 30 days)
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')

Accepted Answer

DGM
DGM on 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')

More Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!