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

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Chandrasekhar
Chandrasekhar am 26 Mär. 2014
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 Kommentare
Andrew
Andrew am 26 Mär. 2014
That worked! Thank you so much, now I can move on to the next step of the program! Thank you again!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by