# MATLAB index problem

1. Dec 3, 2007

### GreenLRan

I'm having a problem getting my graph labels to work. I get an error saying

"??? Index exceeds matrix dimensions.

Error in ==> aeroproject2 at 88
plot(alphaLzero-8:alphaLzero+8,CL(1,1:17)),title('CL vs Alpha'),xlabel('Angle of Attack'),ylabel('CL')"

can anyone help? thanks, and here is the code.

%%%AEM313 Project 2%%%

%%see in givens%%
prompt = {'Taper Ratio:','Full Span (b):','Wing Twist (degrees):','Zero Lift AOA (degrees):','Sweep Angle (degrees):','M (number of coefficients):'};
title = 'Input';
num_lines = 1;
def = {'.5','5','0','0','22','3'};
answer = inputdlg(prompt,title,num_lines,def);
assignin('base','lamda',answer{1});
assignin('base','b',answer{2});
assignin('base','alpha_GT',answer{3});
assignin('base','alphaLzero',answer{4});
assignin('base','sweep',answer{5});
assignin('base','m',answer{6});
lamda = str2num(lamda)
b = str2num(b)
alpha_GT = str2num(alpha_GT)
alphaLzero = str2num(alphaLzero)
sweep = str2num(sweep)
m = str2num(m)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
S=(2*(.5*b*lamda + 2*(.5 * b * .5 *( .5 * (1-lamda)))));
AR= b^2/S;
d_theta = pi /(2*m);
i=1;
theta{i} = pi / 2;
while i <= m
i=i+1;
theta{i} = theta{i-1} - d_theta;
end
for p = 1:m
n = 1;
for j = 1:m
%%%using + in Chord(theta_naught) for right wing
B(p,j) = 2*b/(pi*(1+(1-lamda)*cos(theta{p}))) * sin(n*theta{p}) + n*sin(n*theta{p})/sin(theta{p});
n=n+2;
end
end
for x = 1:m
y=1;
AOA = alphaLzero - 8;
while AOA <= alphaLzero + 8
alpha = AOA + alpha_GT * cos (theta{x});
C(x,y) = (alpha - alphaLzero)*pi/180;
AOA = AOA + 1;
y=y+1;
end
end
A = inv(B(1:m,1:m))*C(1:m,1:17);
CL = pi*AR*A(1,1:17)
AR
for u = 1:17
g=1;
l=1;
while g <= m * 2 - 1
sum=g*A(l,u)^2;
g=g+2;
l=l+1;
end
CDi(u) = pi*AR*sum;
end
aslope = (CL(10)-CL(9));
AoA= alphaLzero-8:alphaLzero+8;
tau = 2*pi/aslope - 2;
v=1;
if (AR > 4) && (sweep < 10)
figure(1)
plot(AoA,CL),title('CL vs Alpha'),xlabel('Angle of Attack'),ylabel('CL')
end
if (AR < 4) && (sweep < 10)
a=2*pi/(tau^2+3*tau+3)^.5;
for AoA = alphaLzero-8:alphaLzero+8;
CL(v)=a*(AoA - alphaLzero);
v=v+1;
end
figure(1)
plot(alphaLzero-8:alphaLzero+8,CL(1:17)),title('CL vs Alpha'),xlabel('Angle of Attack'),ylabel('CL')
end
if (AR > 4) && (sweep > 10)
sweep = sweep*pi/180;
a = 2*pi*cos(sweep)/(1+cos(sweep)*(1+tau));
for AoA = alphaLzero-8:alphaLzero+8;
CL(v) = a*(AoA - alphaLzero);
v=v+1;
end
CL(1,1:17)
figure(1)
plot(alphaLzero-8:alphaLzero+8,CL(1,1:17)),title('CL vs Alpha'),xlabel('Angle of Attack'),ylabel('CL')
end
if (AR < 4) && (sweep > 10)
sweep = sweep*pi/180;
a=2*pi*cos(sweep)/( (1+(cos(sweep)*(1+tau))^2)^.5 + (cos(sweep)*(1+tau)));
for AoA = alphaLzero-8:alphaLzero+8;
CL=a*(AoA - alphaLzero);
v=v+1;
end
figure(1)
plot(alphaLzero-8:alphaLzero+8,CL(1:17)),title('CL vs Alpha'),xlabel('Angle of Attack'),ylabel('CL')
end

2. Dec 3, 2007

### J77

Check the size of CL:

size(CL)

3. Dec 3, 2007

### GreenLRan

I checked the size and it gave me
ans =

1 17
which is the same size as alphaLzero-8:alphaLzero+8

4. Dec 3, 2007

### Dr Transport

check and see if they are both column or row vectors. your error look like that may be the problem.

5. Dec 3, 2007

### GreenLRan

they are both 1 row 17 columns

6. Dec 4, 2007

### J77

"plot(alphaLzero-8:alphaLzero+8,CL(1:17))"

Try (for clarity):

AA=alphaLzero-8:alphaLzero+8;

plot(AA(1,:),CL(1,

(of course, size(AA) should be [1 17])

7. Dec 4, 2007

### GreenLRan

That doesn't work either, Same error....."Index exceeds matrix dimensions"

8. Dec 4, 2007

### GreenLRan

I found that it's a problem with the title() command.. for some reason the title command is causing the error. I took it out, and it works fine.

9. Dec 4, 2007

### GreenLRan

%%%AEM313 Project 2%%%

%%see in givens%%
prompt = {'Taper Ratio:','Full Span (b):','Wing Twist (degrees):','Zero Lift AOA (degrees):','Sweep Angle (degrees):','M (number of coefficients):','Re','lam or turb (1 or 2)'};
title = 'Input';
num_lines = 1;
def = {'.5','5','0','0','22','3','500000','1'};
answer = inputdlg(prompt,title,num_lines,def);
assignin('base','lamda',answer{1});
assignin('base','b',answer{2});
assignin('base','alpha_GT',answer{3});
assignin('base','alphaLzero',answer{4});
assignin('base','sweep',answer{5});
assignin('base','m',answer{6});
assignin('base','Re',answer{7});
assignin('base','desig',answer{8});
lamda = str2num(lamda)
b = str2num(b)
alpha_GT = str2num(alpha_GT)
alphaLzero = str2num(alphaLzero)
sweep = str2num(sweep)
m = str2num(m)
Re = str2num(Re)
desig = str2num(desig)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
S=(2*(.5*b*lamda + 2*(.5 * b * .5 *( .5 * (1-lamda)))));
AR= b^2/S;
d_theta = pi /(2*m);
i=1;
theta{i} = pi / 2;
while i <= m
i=i+1;
theta{i} = theta{i-1} - d_theta;
end
for p = 1:m
n = 1;
for j = 1:m
%%%using + in Chord(theta_naught) for right wing
B(p,j) = 2*b/(pi*(1+(1-lamda)*cos(theta{p}))) * sin(n*theta{p}) + n*sin(n*theta{p})/sin(theta{p});
n=n+2;
end
end
for x = 1:m
y=1;
AOA = alphaLzero - 8;
while AOA <= alphaLzero + 8
alpha = AOA + alpha_GT * cos (theta{x});
C(x,y) = (alpha - alphaLzero)*pi/180;
AOA = AOA + 1;
y=y+1;
end
end
A = inv(B(1:m,1:m))*C(1:m,1:17)
CL = pi*AR*A(1,1:17);
AR
%%%% calculations based on AR and sweep %%%%%
aslope = (CL(10)-CL(9));
AoA= alphaLzero-8:alphaLzero+8;
tau = 2*pi/aslope - 2;
v=1;
%%if (AR > 4) && (sweep < 10)
%% figure(1)
%% plot(AoA,CL),title('CL vs Alpha'),xlabel('Angle of Attack'),ylabel('CL')
%%end
if (AR < 4) && (sweep < 10)
a=2*pi/(tau^2+3*tau+3)^.5;
for AoA = alphaLzero-8:alphaLzero+8;
CL(v)=a*(AoA - alphaLzero);
v=v+1;
end
end
if (AR > 4) && (sweep > 10)
sweep = sweep*pi/180;
a = 2*pi*cos(sweep)/(1+cos(sweep)*(1+tau));
for AoA = alphaLzero-8:alphaLzero+8;
CL(v) = a*(AoA - alphaLzero);
v=v+1;
end
end
if (AR < 4) && (sweep > 10)
sweep = sweep*pi/180;
a=2*pi*cos(sweep)/( (1+(cos(sweep)*(1+tau))^2)^.5 + (cos(sweep)*(1+tau)));
for AoA = alphaLzero-8:alphaLzero+8;
CL(v)=a*(AoA - alphaLzero);
v=v+1;
end
end

%%%% induced drag %%%%
for u = 1:17
g=3;
l=2;
del=g*(A(l,u)/A(1,u))^2;
while l<m %% g <= m * 2 - 1
g=g+2;
l=l+1;
del = del + g*(A(l,u)/A(1,u))^2;
if A(l,u) == 0
del = 0;
end
end

CDi(1,u) = CL(1,u)^2*(1+del)/(pi*AR)
end
e = 1/(1+del);
%%% skin friction drag %%%
mslope = -(1-lamda)/(b/2);
dx=.1*b/2;
Cf_lam = 1.328/(Re)^.5 * 2;
Cf_turb = .074/(Re)^.2 * 2;
while dx <= b/2
y = mslope*dx + 1;
Re_y = Re*y;
Cf_lam = Cf_lam + 1.328/(Re_y)^.5 * 4;
Cf_turb = Cf_turb + .074/(Re_y)^.2 * 4;
dx=dx+.1*b/2;
end
if desig == 1
CD = CDi(1:17) + Cf_lam;
end
if desig == 2
CD = CDi(1:17) + Cf_turb;
end
MAC= 2/S*(lamda^2+lamda+1)*b/6;
AoA=alphaLzero-8:alphaLzero+8;
figure(1)
%%plot (AoA(1,9),CD(1,9)),title('CD vs Alpha'),xlabel('Angle of Attack'),ylabel('CD')
%%hold on
%%title('CD vs Alpha')
xlabel('Angle of Attack')
ylabel('CD')
plot (AoA(1,:),CD(1,,xlabel('Angle of Attack'),ylabel('CD')

figure(2)
plot (AoA(1,:),CL(1,,xlabel('Angle of Attack'),ylabel('CL')

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook