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')
댓글 수: 0
채택된 답변
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 Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!