How can fix index exceeds matrix error

mn=input('Modül Giriniz:');
T=input('Teeth Numbers :');
at=input('Transverse pressure angle: ');
ad=input('Addendum Coef: ');
de=input('Deddendum Coef :');
Hobtip=input('Hob Tip Radius coef: ');
rg=mn*T/2;
rr=rg-(de*mn);
br=rg*cosd(at);
tr=rg+(ad*mn);
b=(tr-br)/180;
r=br;
a=1;
r2=num2cell(br:b:tr);
inva=tand(at)-(at*pi/180);
ctt1=pi*mn/2;
% Involute Curves
while r<=tr
r=r+b;
a=a+1;
end
for i=1:1:a
teta{i}=acosd(br/r2{i});
invteta{i}=tand(teta{i})-(teta{i}*pi/180);
ctt2{i}=2*r2{i}*((0.5*ctt1/rg)+inva-invteta{i});
B{i}=0.5*ctt2{i}/r2{i};
x{i}=r2{i}*sin( B{i});
y{i}=r2{i}*cos(B{i});
leftx{i}=-1*r2{i}*sin(B{i});
end
% Trochoid Curves
B_tr=(de*mn)-(Hobtip*mn);
L=(pi*mn/4.0)-(B_tr*tand(at))-(Hobtip*mn/(cosd(at)));
W=((((pi*mn)/2.0)-L)/rg);
E=0;
e=E;
Emax=50*pi/180;
tro=Emax/179;
o=1;
E2=num2cell(0:tro:Emax);
while (e<=Emax)
e=e+tro;
o=o+1;
end
for q=1:o
Yz{q}=((rg-B_tr)*cos(E2{q}))+((rg*E2{q}*sin(E2{q})));
Xz{q}=(rg*E2{q}*cos(E2{q}))-((rg-B_tr)*sin(E2{q}));
DXZ{q}=(-(rg*E2{q}).*sin(E2{q}))+((B_tr*cos(E2{q})));
DYZ{q}=(B_tr*sin(E2{q}))+((rg*E2{q})*cos(E2{q}));
if(E==0)
A{q}=90*pi/180.;
end
A{q}=atan(DXZ{q}./DYZ{q});
Xt{q}=Xz{q}+((Hobtip*mn).*cos(A{q}));
Yt{q}=Yz{q}-(Hobtip*mn.*sin(A{q}));
Xtr{q}=Yt{q}.*sin(W)-Xt{q}.*cos(W);
Ytr{q}=Yt{q}.*cos(W)+Xt{q}.*sin(W);
leftXtr{q}=-1.*(Yt{q}.*sin(W)-Xt{q}.*cos(W));
end
% Tooth Curves
% Involute ones
plot(cell2mat(x),cell2mat(y));
hold on
plot(cell2mat(leftx),cell2mat(y));
hold on
% Trochoid Ones
plot(cell2mat(Xtr),cell2mat(Ytr));
hold on
plot(cell2mat(leftXtr),cell2mat(Ytr));

4 Comments

index exceeds matrix dimensions "teta{i}=acosd(br/r2{i})
"yz{q}=((rg-b_tr)*cos(e2{q}))+((rg*e2{q}*sin(e2{q})))"
"xz{q}=(rg*e2{q}*cos(e2{q}))-((rg-b_tr)*sin(e2{q})) "
Have a read here (or here for more general advice). It will greatly improve your chances of getting an answer.
What have you tried to solve this problem yourself? Have you checked the dimensions of the arrays you're indexing when the error occurs?
Could you please define your inputs? So we can run your code?
mn=input('Modül Giriniz:');
T=input('Teeth Numbers :');
at=input('Transverse pressure angle: ');
ad=input('Addendum Coef: ');
de=input('Deddendum Coef :');
Hobtip=input('Hob Tip Radius coef: ');
BAHADIR Karba
BAHADIR Karba on 30 Jan 2019
Edited: BAHADIR Karba on 30 Jan 2019
case 1 :
mn=3
T=20
at=20
ad=1.0
de=1.25
Hobtip=0.38
whenever i used any pertinent inputs programs give errors especially like that
indexing exceed,actually main problem due to double / cells
"teta{i}=acosd(br/r2{i})
"yz{q}=((rg-b_tr)*cos(e2{q}))+((rg*e2{q}*sin(e2{q})))"
"xz{q}=(rg*e2{q}*cos(e2{q}))-((rg-b_tr)*sin(e2{q})) "
Even i take an error like that sometimes,if ı rewrite plots on the command section can show plots correctly,But most of trying give errors and program stopped due to errors

Sign in to comment.

 Accepted Answer

Your first error occurs with teta{i} = acosd(br/r2{i}); because r2 has one less element than the max values of i. I would suggest initializing a as 0 instead of 1.
I did not encounter the other errors.

1 Comment

Yes,I forgot this a and o values must be started from 0;and also solved.
Many thanks ,
Best regards

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!