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

조회 수: 1 (최근 30일)
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')

채택된 답변

DGM
DGM 2021년 11월 22일
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')

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by