Help With Error: "Attempted to access S_0(2); index out of bounds because numel(S_0)=1."

조회 수: 3 (최근 30일)
Hi, so I'm trying to get this part of the program running in matlab, and the error, "Attempted to access S_0(2); index out of bounds because numel(S_0)=1." comes up. here's what I have of the code so far. I'm pretty new to matlab, so I don't know all the functions. I'm trying to find the sum of S_0 without using the "sum" function. Please help asap I need this fast!
Here's the code:
% Inputs and Equations that Calculate the Equations for the Coefficient C_l
f = input('Please Enter the First Digit of the NACA Number'); % Input for the Max. Camber
s = input('Please Enter the Second Digit of the NACA Number'); % Input for the Position of Max. Camber
theta = input('Please Enter Angle of Attack in Degrees'); % Angle of Attack in Degrees
M = f/100; % Calculates the Maximum Camber of the Wing
P = s/10; % Calculates the Position of the Maximum Camber of the Wing
x = .5*(1+cos(theta)); % Distance
n = 180/(theta)+1; % Calculates the Number of Rectangles to be Used for the Integral
% Calculation of dy_c/dx for Values of Different x
if x>= 0 && x<=P;
dy_c1_dx = (M/P^2)*(2*P-2*x); % This is the Gradient if 0<=X and X<=P
elseif x>=P && x<=1;
dy_c2_dx = (M/(1-P)^2)*(2*P-2*x); % This is the Gradient if P<=X and X<=1
end
S_0 = 0
S_1 = 0
for i = 1:n
if x>=0 && x<= P;
S_0(i) = S_0(i)+(dy_c1_dx);
S_1(i) = S_1(i)+(dy_c1_dx)*cos(theta);
elseif x> P && x<=1;
S_0(i) = S_0(i)+(dy_c2_dx);
S_1(i) = S_1(i)+(dy_c2_dx)*cos(theta);
end
end

채택된 답변

Chandrasekhar
Chandrasekhar 2014년 3월 26일
In the code u have declared S_0 and S_1 as scalars and you are trying to access them as vectors in the for loop.S_0 and S_1 has only one element where as you are trying to access the second element of S_0 and S_1 which doesnt exist
  댓글 수: 4
Andrew
Andrew 2014년 3월 26일
That worked! Thank you so much, now I can move on to the next step of the program! Thank you again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by