Prev: Percentage display on Y-axis of Histogram
Next: GUI: How to embed the Biograph Viewer in the GUI?
From: John on 24 Jan 2010 06:01 Hi, I have created a code which works fine for i=1, i=2, i=3 etc but if I have it done in a loop (e.g. for i=1:3) there is an error message saying "Subscript indices must either be real positive integers or logicals" for i=1 <code> ---->works end for i=2 <code> ----> works end for i=1:2 <code> ----> DOESN'T work!!!! WHY?!? end The error message comes at a function call inside the code, which features a double sum of elements of a M x M matrix. Any clues on what I should try out? PS: The code is kinda big so I 'll send it if you think it's needed
From: Jan Simon on 24 Jan 2010 06:13 Dear John! > I have created a code which works fine for i=1, i=2, i=3 etc but if I have it done in a loop (e.g. for i=1:3) there is an error message saying "Subscript indices must either be real positive integers or logicals" > > for i=1 > <code> ---->works > end > > for i=2 > <code> ----> works > end > > for i=1:2 > <code> ----> DOESN'T work!!!! WHY?!? > end > > The error message comes at a function call inside the code, which features a double sum of elements of a M x M matrix. Any clues on what I should try out? > PS: The code is kinda big so I 'll send it if you think it's needed It is not possible to give you a satisfying answer based on this problem description. Most likely you do not have to post the complete code, but at least the line which caused the error. You can take a look into the concerned variables with: dbstop if error Then the debugger stops in the line, which causes the error and you can inspect the variables by showing them in the command line. Good luck, Jan
From: John on 24 Jan 2010 06:23 Hi Jan, here are parts of the code: MAIN CODE: <input of constants> for l=1:2 angle=fibor(l); Stress component calculation Q=StiffMat(angle,E1,E2,G12,n12); Qxx=Q(1,1); Qxy=Q(1,2); Qyy=Q(2,2); Qss=Q(3,3); DSx=DSx(Qxy,Qyy,a,b,N,M,x,y,x1,y1,P,h0,k,fibor,z,E1,E2,G12,n12); sx=(a^2/pi^2)*z(l)*DSx; %x stress component DSy=DSy(Qxy,Qyy,a,b,N,M,x,y,x1,y1,P,h0,k,fibor,z,E1,E2,G12,n12); sy=(a^2/pi^2)*z(l)*DSy; %y stress component R=a/b; DSs=DSs(a,b,N,M,x,y,x1,y1,P,h0,k,fibor,z,E1,E2,G12,n12); ss=-(2*a^2*R/pi^2)*Qss*z(l)*DSs; % s stress component TH=TsaiHill(sx,sy,ss,X,Xdot,Y,Ydot,S,M,angle); Max(l)=max(TH) end DSx FUNCTION (DSy and DSs don't work either, but they're similar): %x Double Sum calculation function [DSx]=DSx(Qxx,Qxy,a,b,N,M,x,y,x1,y1,P,h0,k,fibor,z,E1,E2,G12,n12) R=a/b; DSx=zeros(M,M); Sum1=0; Sum2=0; for i=1:M for j=1:M for m=1:N for n=1:N Quotient=Quot(m,n,a,b,x1,y1,P,h0,k,fibor,z,E1,E2,G12,n12); X=Quotient*(Qxx*m^2+Qxy*n^2*R^2)*sin(m*pi*x(i)/a)*sin(n*pi*y(i)/b); Sum1=Sum1+X; end Sum2=Sum2+Sum1; Sum1=0; end DSx(i,j)=Sum2; Sum2=0; end end end
From: John on 24 Jan 2010 07:12 OK FOUND IT!!! :D For other people having the same problem: NEVER NAME A VARIABLE WITH THE SAME NAME AS THE FUNCTION! eg. DSx=DSx(..........) INSTEAD, USE e.g. DSX=DSx(.......)
|
Pages: 1 Prev: Percentage display on Y-axis of Histogram Next: GUI: How to embed the Biograph Viewer in the GUI? |