Prev: uitable
Next: changing the sign of a vector
From: alfann on 2 Jun 2010 06:55 Hi I don't know about my problem in while loop I put inside the while loop this equation: Total=Total+Tot; and Tot equals to value but the problem is about Total which showed me equal to zero???!!!! Just to make sure: I set: Total=0; before the while loop. Could you help me?
From: Luca Zanotti Fragonara on 2 Jun 2010 11:27 alfann <alfann.net(a)hotmail.com> wrote in message <1570042142.266068.1275490591914.JavaMail.root(a)gallium.mathforum.org>... > Hi > I don't know about my problem in while loop > I put inside the while loop this equation: > > Total=Total+Tot; > > and Tot equals to value > > but the problem is about Total which showed me equal to zero???!!!! > > > Just to make sure: > I set: > Total=0; > before the while loop. > > Could you help me? 1) I think that you have imposed a bad logical condition on the while, and the code jump your while loop. 2) It is always better to post the complete code, so it is easier to debug it.
From: alfann on 2 Jun 2010 07:51 for j = 1:a %columns for i = 1:b %Rows count_row=0; Total=0; count_all=0; R1_count=0; L1_count=0; T1_count=0; D1_count=0; while(U3(i+count_row,j)==1 && i~=1 && j~=1 && i~=b && j~=a) if(U3(i+count_row,j+1)~=1) %clc. right R1=U1(i+count_row,j+1); R1_count=R1_count+1; else R1=0; R1_count=0; end if(U3(i+count_row,j-1)~=1)%clc. left L1=U1(i+count_row,j-1); L1_count=L1_count+1; else L1=0; L1_count=0; end if(U3(i+count_row+1,j)~=1)%clc. top T1=U1(i+count_row+1,j); T1_count=T1_count+1; else T1=0; T1_count=0; end if(U3(i+count_row-1,j)~=1)%clc. down D1=U1(i+count_row-1,j); D1_count=D1_count+1; else D1=0; D1_count=0; end Tot=R1+L1+T1+D1; Total=Total+Tot; Count=R1_count+L1_count+T1_count+D1_count; count_all=count_all+Count; count_row=count_row+1; end end end
From: Walter Roberson on 2 Jun 2010 12:26 alfann wrote: > for j = 1:a %columns > > > for i = 1:b %Rows > count_row=0; > Total=0; You overwrite Total with 0 for every row > while(U3(i+count_row,j)==1 && i~=1 && j~=1 && i~=b && j~=a) And there, on the last iteration, the row (i) will be b and so the while loop will not execute, which will leave Total sitting at 0.
|
Pages: 1 Prev: uitable Next: changing the sign of a vector |