フィルターのクリア

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

2 ビュー (過去 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 Center および File ExchangeSubplots についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by