Subscript indices must either be real positive integers or logicals, this error occurs when i run my program
Show older comments
below is my program, please help me to resolve the issue. %fourier transform analysis of single sided linear induction motor %program for calculating thrust and normal forces pi=3.14;mo=4*pi*1e-7; jz=sqrt(-1); k=input ('Enter 1 for slim or 2 for dslim'); if k==1 m2= input ('Enter the permeability for Back iron'); sig2= input('enter the conductivity of iron'); d2= input ('Enter the thickness of back iron'); mr2=m2*mo A= input ('Enter the value of A'); B= input ('Enter the value of B'); C= input ('Enter the value of C'); I1= input ('Enter the value of the current'); P= input ('Enter the number of poles'); f= input ('Enter the frequency'); L= input ('Enter the length of the stator'); q= input ('Enter the slots/pole/phase'); tow= input ('Enter the value of pole pitch'); sig1= input ('Enter the conductivity of reaction rail'); ts= input ('Enter the value of slot pitch'); b= input ('Enter the value of coil pitch'); d1= input ('Enter the thickness of secondary'); g= input ('Enter the length of air gap'); N= input ('Enter the number of turns'); h= input ('Enter the slack height'); Lc= input ('Enter the gap between primaries'); n= input ('Enter the harmonic value'); D= input ('Enter the width of secondary'); W= input ('Enter the width of primary'); h= input ('Enter the value of dzeeta'); nc= input ('Enter the number of conductors'); slot= input ('Enter the number of slots'); sig1= input ('Enter the conductivity of secondary'); KL=pi/tow; %wave constant w=2*pi*f; vs=2*tow*f; m1=mo; m3=mo; wind=0.995; cur=3; j=(2*nc*slot*cur*wind*1.414)/L; x=1; for s=1:11 fsum1=0; fsum2=0; fsum3=0; fsum4=0; s1(x)=(s-1)/10; v(x)=(1-s1(x))*vs; for KL=1:n for i=1:351 if i==1 Z=i-201; else Z=h+(i-201); end end c(i)=Z; LN=0.5*(2*KL-1)*pi/D; CN=2*(sin(LN*W))/(LN*D); ETA=(Z^2+LN^2)^0.5; if k==1 XYN=(ETA^2+jz*w*m1*sig1+jz*Z*v(x)*m1*sig1)^0.5; GYN=(ETA^2+jz*w*m2*sig2+jz*Z*v(x)*m2*sig2)^0.5; XC=XYN*C; GYNB=GYN*(B-C); ETAYB=ETA*(A-B); TC=sinh(XC)/cosh(XC); CE=cosh(ETAYB); SE=sinh(ETAYB); CG=cosh(GYNB); SG=sinh(GYNB); W1=CE*CG*(1+(m1*ETA*TC/(mo*XYN))); W2=SE*CG*(1+(mo*XYN*TC/(m1*ETA))); W3=CE*SG*((m2*ETA/(mo*GYN)+(m2*XYN))); W4=SE*SG*((mo*GYN/(m2*ETA))+(m1*GYN*TC/(m2*XYN))); WN=W1+W2+W3+W4; K1=CE*CG*(1+(mo*XYN*TC/(m1*ETA))); K2=SE*CG*(1+(m1*ETA*TC/(mo*XYN))); K3=CE*SG*(((mo*GYN)/(m2*ETA))+(m1*GYN*TC)/(m2*XYN)); K4=SE*SG((m2*ETA)/(mo*GYN)+(m2*XYN*TC)/(m1*GYN)); KN=K1+K2+K3+K4; ETA1=LN; XYN1=(ETA^2+jz*w*m1*sig1)^0.5; GYN1=(ETA^2+jz*w*m2*sig2)^0.5; XC1=XYN1*C; GYNB1=GYN1*(B-C); ETAYB1=ETA1*(A-B); TC1=sinh(XC1)/cosh(XC1); CE1=cosh(ETAYB1); SE1=sinh(ETAYB1); CG1=cosh(GYNB1); SG1=sinh(GYNB1); W11=CE1*CG1*(1+(m1*ETA1*TC1/(mo*XYN1))); W21=SE1*CG1*(1+(mo*XYN1*TC1/(m1*ETA1))); W31=CE1*SG1*((m2*ETA1/(mo*GYN1))+(m2*XYN1*TC1/(m1*GYN1))); W41=SE1*SG1*((mo*GYN1/(m2*ETA1))+(m1*GYN1*TC1/(m2*XYN1))); WN1=W11+W21+W31+W41;
K11=CE1*CG1*(1+(mo*XYN1*TC1/(m1*ETA1))); K21=SE1*CG1*(1+(m1*ETA1*TC1/(mo*XYN1))); K31=CE1*SG1*(((mo*GYN1)/(m2*ETA1))+(m1*GYN1*TC1)/(m2*XYN1)); K41=SE1*SG1*(((m2*ETA1)/(mo*GYN1))+(m2*XYN1*TC1)/(m1*GYN1)); KN1=K11+K21+K31+K41;
WN2=WN*WN1; KN2=KN*KN1;
csc=J*J*m3/pi; FTA1(i)=(csc*(1-(cos(Z*L+KL*L)))*CN*(ETA/LN)*(sin(LN*W))*imag(WN/KN))/(Z*(Z+KL)*(Z+KL)); FTA2(i)=((-csc*D/4)*CN^2*(1-cos(Z*L))/(Z+KL)^2); FTA31=((1-cos(Z*L))*ETA^2*abs(WN/KN)^2/(Z^2*(Z+KL)^2)); FTA32=((1-cos(Z*L))*LN^2*abs(WN1/KN1)^2/(Z^2*KL)); FTA33=(ETA*LN*2*(1-cos(Z*L))*imag(WN2/(KN*KN))/(KL*Z^2*(Z+KL))); FTA3(i)=((csc*D/4)*CN^2*(FTA31+FTA32-FTA33)); FTA41=((1-cos(Z*L))/(Z^2*(Z+KL)^2)); FTA42=((1-cos(Z*L))/(Z^2*KL^2)); FTA43=(2*(1-cos(Z*L))/(KL*Z^2*(Z+KL))); FTA4(i)=(-cos*D/4)*LN^2*(FTA41+FTA42+FTA43); end if k==2 GYN=(ETA^2+jz*w*m2*sig2+jz*Z*v(x)*m2*ig2)^0.5; GYNB=GYN*B; Y=A; ETAYB=ETA*(Y-B); ETAAB=ETA*(A-B); GN1=cosh(ETAYB)*cosh(GYNB); GN2=(GYN/ETA)*sinh(ETAYB)*sinh(GYNB); HN1=ETA*sinh(ETAAB)*cosh(GYNB); HN2=GYN*cosh(ETAAB)*sinh(GYNB); GN=GN1+GN2; HN=HN1+HN2; GNHN=GN/HN; csc=J*J*m3*4/pi; FTA(i)=(csc*(1-(cos(Z*L+KL*L)))*CN*(ETA^2/LN)*(sin(LN*W))*imag(GNHN))/(Z*(Z+KL)*(Z+KL)); end end fsum1=fsum1+h*trapz(FTA1); if k==2 fsum2=fsum2+h*trapz(FTA2); fsum3=fsum3+h*trapz(FTA3); fsum4=fsum4+h*trapz(FTA4); end end FT1(x)=fsum1; if k==2 FT2(x)=fsum2+fsum3+fsum4; x=x+1; end end figure(2); plot(s1,FT1); figure(3); plot(s1,FT2); end
below are the values entered by me,
Enter 1 for slim or 2 for dslim1 Enter the permeability for Back iron150 enter the conductivity of iron1.0*10^7 Enter the thickness of back iron2
mr2 =
1.8840e-04
Enter the value of A3 Enter the value of B5 Enter the value of C7 Enter the value of the current4 Enter the number of poles2 Enter the frequency50 Enter the length of the stator25 Enter the slots/pole/phase3 Enter the value of pole pitch.094 Enter the conductivity of reaction rail3.5*10^7 Enter the value of slot pitch1.5 Enter the value of coil pitch7 Enter the thickness of secondary.5 Enter the length of air gap1.5 Enter the number of turns300 Enter the slack height3.7 Enter the gap between primaries.03 Enter the harmonic value5 Enter the width of secondary.5 Enter the width of primary9.5 Enter the value of dzeeta.05 Enter the number of conductors180 Enter the number of slots7 Enter the conductivity of secondary5.96*10^7 Subscript indices must either be real positive integers or logicals.
1 Comment
Geoff Hayes
on 3 May 2014
Edited: Geoff Hayes
on 3 May 2014
Please format the above for readability - highlight the code portion and press the {}Code button. Or better yet, please include the code as a file attachment to your question, saving the above space for pertinent information.
The error Subscript indices must either be real positive integers or logicals typically means that the code is trying to access an element in an array or matrix using an index that is non-positive (so is negative or zero) or is not an integer (so is a rational number). OR it means that there is a bug in the code where it is treating something like an array when in fact it isn't:
x=1;
y=x(1.445);
when what you really wanted (in the above) was:
x=1;
y=x*(1.445);
To solve this problem, you should a breakpoint at the line just after the code that calls for the last input from the user ( sig1= input ('Enter the conductivity of secondary');) and then step through the code from that point on until the error is raised. (Actually, this should already be known - if the above error was generated then usually the line number for that error is returned to the console too…) Put a breakpoint at that line and try again, and just when the line that generates the error is about to be called, look at the index values to that array or matrix - are they non-positive? are they rational? is anything missing?
Answers (1)
Jan
on 3 May 2014
Using the debugger is the best way to find the reason of an error. So type in the command window:
dbstop if error
and start your program again. Then Matlab stops at the failing line. Now check the variables uesd as indices and find out, why a value is not positive or no integer.
Please notice, that the complete error message conatins the information about the failing line also. Therefore it is recommende to post the complete error message, when you want others to assist you.
A hint: The lack of comments reduces the chance to debug your code substantially. Using such a pile of input() commands to define the inputs is less smart than defining input arguments for the function. With inputs it would be trivial to post the command, which reproduces the error.
Categories
Find more on Symbolic Math Toolbox 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!