f



while loop inside a for loop

Hi, can someone please tell me why "time" (t) is not updated correctly within the while loop? Please run this small code in your machine and you'll know what I'm taking about.

What I want is: for t=1 run the "while loop" until iq<=(numberc-1) then t=2 run the "while loop" again until iq<=(numberc-1), and so on.

Basically, this code runs through all the nonzero elements of A and attempts to divide them individually into two, once a certain time has passed. Please feel free to ask for clarifications.
 
Many thanks in advance.

A=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; ...
         0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
         0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
         0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
         0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
         0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
         0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
         0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
         0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
      
gridx=20;gridy=10; tarea=16;
Td=2;idx=0;iq=1;tsigma=1;

maxc=floor((gridx*gridy)/tarea);     
numberc=max(max(A));

clocks=zeros(25,25);
clocks(1:25,1)=1;

t=1;
for t=1:25 % MCS
	while iq<=(numberc-1)
		[rows,cols]=find(A==iq);
		centroid = mean([rows cols]);
		mxr=max(rows);
		mnr=min(rows);
		mxc=max(cols);
		mnc=min(cols);
		if (length(centroid)==2)
		   ct1=round(centroid(2));
		   ct2=floor(centroid(1));
		end
		% vertical distance
		vds=mxr-mnr;
		
		a=max(max(A));

		%% if time since last division exceeds Td
		t
		if( (t-idx)>Td)             
		   A(mnr:ct2,mnc:mxc)=1+numberc; 
		end

		b=max(max(A));
		c=b-a;
		if c>0; 
			tsigma=t;
			clocks(iq,t)=tsigma;
			
			af=find((clocks(iq,:))>0);
			bf=af(end);     
			idx=clocks(iq,bf);      
		end

		numberc=max(max(A)); 

	iq=iq+1;
	   
	end
end
0
MA87 (38)
3/1/2012 12:32:14 PM
comp.soft-sys.matlab 211266 articles. 17 followers. lunamoonmoon (258) is leader. Post Follow

5 Replies
3125 Views

Similar Articles

[PageSpeed] 47

"Emma Robertson" wrote in message <jinq8e$j1f$1@newscl01ah.mathworks.com>...
> Hi, can someone please tell me why "time" (t) is not updated correctly within the while loop? Please run this small code in your machine and you'll know what I'm taking about.
> 
> What I want is: for t=1 run the "while loop" until iq<=(numberc-1) then t=2 run the "while loop" again until iq<=(numberc-1), and so on.
> 
> Basically, this code runs through all the nonzero elements of A and attempts to divide them individually into two, once a certain time has passed. Please feel free to ask for clarifications.
>  
> Many thanks in advance.
> 
> A=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; ...
>          0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
>          0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
>          0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
>          0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
>          0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
>          0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
>          0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
>          0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
>          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
>       
> gridx=20;gridy=10; tarea=16;
> Td=2;idx=0;iq=1;tsigma=1;
> 
> maxc=floor((gridx*gridy)/tarea);     
> numberc=max(max(A));
> 
> clocks=zeros(25,25);
> clocks(1:25,1)=1;
> 
> t=1;
> for t=1:25 % MCS
> 	while iq<=(numberc-1)
> 		[rows,cols]=find(A==iq);
> 		centroid = mean([rows cols]);
> 		mxr=max(rows);
> 		mnr=min(rows);
> 		mxc=max(cols);
> 		mnc=min(cols);
> 		if (length(centroid)==2)
> 		   ct1=round(centroid(2));
> 		   ct2=floor(centroid(1));
> 		end
> 		% vertical distance
> 		vds=mxr-mnr;
> 		
> 		a=max(max(A));
> 
> 		%% if time since last division exceeds Td
> 		t
> 		if( (t-idx)>Td)             
> 		   A(mnr:ct2,mnc:mxc)=1+numberc; 
> 		end
> 
> 		b=max(max(A));
> 		c=b-a;
> 		if c>0; 
> 			tsigma=t;
> 			clocks(iq,t)=tsigma;
> 			
> 			af=find((clocks(iq,:))>0);
> 			bf=af(end);     
> 			idx=clocks(iq,bf);      
> 		end
> 
> 		numberc=max(max(A)); 
> 
> 	iq=iq+1;
> 	   
> 	end
> end

If you simply display the value of t between the for and while statements, you will see that t is incrementing from 1 to 25.  So, what must be happening is that the first time through the for loop iq is less than or equal to (numberc-1) and thus the while loop executes and the value of t=1 is displayed each time thru the while loop.  After that (for the other 24 times thru the for loop) iq is greater than (numberc-1) so whats inside the while loop never gets executed and thus t does not get displayed.

Perhaps you need to reset iq or numberc between the for and while loops.  Or something similar.
0
someone3 (1980)
3/1/2012 3:32:12 PM
"someone" wrote in message <jio4ps$ohn$1@newscl01ah.mathworks.com>...
> "Emma Robertson" wrote in message <jinq8e$j1f$1@newscl01ah.mathworks.com>...
> > Hi, can someone please tell me why "time" (t) is not updated correctly within the while loop? Please run this small code in your machine and you'll know what I'm taking about.
> > 
> > What I want is: for t=1 run the "while loop" until iq<=(numberc-1) then t=2 run the "while loop" again until iq<=(numberc-1), and so on.
> > 
> > Basically, this code runs through all the nonzero elements of A and attempts to divide them individually into two, once a certain time has passed. Please feel free to ask for clarifications.
> >  
> > Many thanks in advance.
> > 
> > A=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; ...
> >          0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
> >          0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
> >          0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
> >          0 0 1 1 1 1 3 3 3 3 5 5 5 5 7 7 7 7 0 0; ...
> >          0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
> >          0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
> >          0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
> >          0 0 2 2 2 2 4 4 4 4 6 6 6 6 8 8 8 8 0 0; ...
> >          0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
> >       
> > gridx=20;gridy=10; tarea=16;
> > Td=2;idx=0;iq=1;tsigma=1;
> > 
> > maxc=floor((gridx*gridy)/tarea);     
> > numberc=max(max(A));
> > 
> > clocks=zeros(25,25);
> > clocks(1:25,1)=1;
> > 
> > t=1;
> > for t=1:25 % MCS
> > 	while iq<=(numberc-1)
> > 		[rows,cols]=find(A==iq);
> > 		centroid = mean([rows cols]);
> > 		mxr=max(rows);
> > 		mnr=min(rows);
> > 		mxc=max(cols);
> > 		mnc=min(cols);
> > 		if (length(centroid)==2)
> > 		   ct1=round(centroid(2));
> > 		   ct2=floor(centroid(1));
> > 		end
> > 		% vertical distance
> > 		vds=mxr-mnr;
> > 		
> > 		a=max(max(A));
> > 
> > 		%% if time since last division exceeds Td
> > 		t
> > 		if( (t-idx)>Td)             
> > 		   A(mnr:ct2,mnc:mxc)=1+numberc; 
> > 		end
> > 
> > 		b=max(max(A));
> > 		c=b-a;
> > 		if c>0; 
> > 			tsigma=t;
> > 			clocks(iq,t)=tsigma;
> > 			
> > 			af=find((clocks(iq,:))>0);
> > 			bf=af(end);     
> > 			idx=clocks(iq,bf);      
> > 		end
> > 
> > 		numberc=max(max(A)); 
> > 
> > 	iq=iq+1;
> > 	   
> > 	end
> > end
> 
> If you simply display the value of t between the for and while statements, you will see that t is incrementing from 1 to 25.  So, what must be happening is that the first time through the for loop iq is less than or equal to (numberc-1) and thus the while loop executes and the value of t=1 is displayed each time thru the while loop.  After that (for the other 24 times thru the for loop) iq is greater than (numberc-1) so whats inside the while loop never gets executed and thus t does not get displayed.
> 
> Perhaps you need to reset iq or numberc between the for and while loops.  Or something similar.

Thanks for your reply. I have tried this but for some reason it is not giving me what I want.
I'd like the code to run through all elements of A at each time step and examine the given condition.
Any one else can help please?
0
MA87 (38)
3/1/2012 4:37:17 PM
"Emma Robertson" wrote in message <jio8jt$99l$1@newscl01ah.mathworks.com>...
> Thanks for your reply. I have tried this but for some reason it is not giving me what I want.
> I'd like the code to run through all elements of A at each time step and examine the given condition.
> Any one else can help please?
- - - - - - -
  You should pay more attention to what "someone" has told you, Emma.  I'll put it in different terms.  After the while-loop exits in the first t = 1 run, it is because the iq<=(numberc-1) condition has become false.  The variable 'iq' is not altered when the second run with t = 2 is begun, (the iq = iq + 1 step is inside the while-loop.)  That means the iq<=(numberc-1) condition is still false and will continue to be false from then on.  You must do something to iq after leaving the while-loop to allow the next while-loop to begin executing.

Roger Stafford
0
3/1/2012 5:55:16 PM
"Roger Stafford" wrote in message <jiod64$os0$1@newscl01ah.mathworks.com>...
> "Emma Robertson" wrote in message <jio8jt$99l$1@newscl01ah.mathworks.com>...
> > Thanks for your reply. I have tried this 

What exactly have you tried?

> > but for some reason it is not giving me what I want.
> > I'd like the code to run through all elements of A at each time step and examine the given condition.
> > Any one else can help please?
> - - - - - - -
>   You should pay more attention to what "someone" has told you, Emma.  I'll put it in different terms.  After the while-loop exits in the first t = 1 run, it is because the iq<=(numberc-1) condition has become false.  The variable 'iq' is not altered when the second run with t = 2 is begun, (the iq = iq + 1 step is inside the while-loop.)  That means the iq<=(numberc-1) condition is still false and will continue to be false from then on.  You must do something to iq after leaving the while-loop to allow the next while-loop to begin executing.
> 
> Roger Stafford
0
someone3 (1980)
3/1/2012 8:33:20 PM
"someone" wrote in message <jiomeg$s7m$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jiod64$os0$1@newscl01ah.mathworks.com>...
> > "Emma Robertson" wrote in message <jio8jt$99l$1@newscl01ah.mathworks.com>...
> > > Thanks for your reply. I have tried this 
> 
> What exactly have you tried?
> 
> > > but for some reason it is not giving me what I want.
> > > I'd like the code to run through all elements of A at each time step and examine the given condition.
> > > Any one else can help please?
> > - - - - - - -
> >   You should pay more attention to what "someone" has told you, Emma.  I'll put it in different terms.  After the while-loop exits in the first t = 1 run, it is because the iq<=(numberc-1) condition has become false.  The variable 'iq' is not altered when the second run with t = 2 is begun, (the iq = iq + 1 step is inside the while-loop.)  That means the iq<=(numberc-1) condition is still false and will continue to be false from then on.  You must do something to iq after leaving the while-loop to allow the next while-loop to begin executing.
> > 
> > Roger Stafford

Sorry for the confusion. I've put "iq=1;" just before the "while loop", and this answers my initial question. But, this directed me to another problem within the code that I'm trying to fix now. Thanks.
0
MA87 (38)
3/1/2012 9:15:21 PM
Reply:

Similar Artilces:

loops in loops
In the attached vi, the one second loop runs at one second and can't be touched.&nbsp; In the ten second loop, the ten second clock is a stand in for a process that generates a finished signal. The problem is once the process is complete, to start it again, leave the one second loop running, and start an additional process that will take less time than 10 seconds. thanks internal loops.vi: http://forums.ni.com/attachments/ni/170/319512/1/internal loops.vi Hi exo, what do you try there? If you start your vi, the value from your stop button will be read and after that, both loops "one" second and "ten" second won�t notice the state change of the stop button. Can you please explain, what you try to do?? Mike Okay, let me try again. I need three loops. Two loops start at the same time one runs fast one runs slow. The slow one is probably independent to the problem. When the second loop is done, it needs to restart and start a third loop that takes less than the second. You have a very basic dataflow problems. Unfortunately, I don't understand your description. &nbsp; I would recommend starting with some basic LabVIEW tutorials. &nbsp; Here are some&nbsp;obvious mistakes: - Your loop cannot read changes in the stop button, because the terminal is outside the loop. - You reset "internal loop" to zero in parallel to the loops. You cannot guarantee that this will happen before the locals are read so you might have a race c...

while loop in a while loop
Hi all, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I am trying to write a program with a while loop within another while loop. When I run the vi both while loops&nbsp; run but then only the inner while loop seems to update, I adjust controls and they have no effect on the indicators. &nbsp; Thanks.. The outer while loop will not update until the inner while loop finishes, at which point the whole dance will start again You need to familiarize with the concept of dataflow programming. Run your VI in "execution highligthing" mode while watching the diagram and you'll get a better feeling on how things work. :) &nbsp; If both loops need to run in parallel, place them next to each other without data dependency. &nbsp; Can you explain what you are trying to do? :) So is it a bad idea to have one within the other if I was them to run simultaniously? Should I put the two whileloops side by side? I have attached the block diagram Thanks &nbsp; Block Diagram.JPG: http://forums.ni.com/attachments/ni/170/319250/1/Block Diagram.JPG sparrowroad wrote:So is it a bad idea to have one within the other if I was them to run simultaniously? Should I put the two whileloops side by side? I have attached the block diagram It all depends what your program should do There are scenarios where stacked loops are appropriate. Typically, one loop is sufficient if you want to run most of the code at 500ms interval, but some p...

LOOP and +LOOP
With LOOP, since the index (I) increases by 1 with each loop iteration, we can test for equality as a means to determine if it's time to exit the loop or not: : TEST 10 0 DO I . LOOP ; TEST 0 1 2 3 4 5 6 7 8 9 Here, when I gets to 10, the loop exits. It's not so easy with +LOOP, since the index can be changed by any arbitrary value on each iteration: : TEST 100 0 DO I . RANDOM +LOOP ; Here, we cannot test for equality. We have to test for crossing a boundary instead, at least as far as I can see. With that in mind, are these following results correct: : TEST 10 0 DO I . 1 +LOOP ; TEST 0 1 2 3 4 5 6 7 8 9 10 (11 iterations) : TEST 10 0 DO I . 3 +LOOP ; TEST 0 3 6 9 (4 iterations) : TEST -30 -7 DO I . -3 +LOOP ; TEST -7 -10 -13 -16 -19 -22 -25 -28 (8 iterations) Regards Mark On Nov 25, 10:34=A0pm, MarkWills <markrobertwi...@yahoo.co.uk> wrote: > With LOOP, since the index (I) increases by 1 with each loop > iteration, we can test for equality as a means to determine if it's > time to exit the loop or not: > > : TEST 10 0 DO I . LOOP ; > TEST > 0 1 2 3 4 5 6 7 8 9 > > Here, when I gets to 10, the loop exits. > > It's not so easy with +LOOP, since the index can be changed by any > arbitrary value on each iteration: > > : TEST 100 0 DO I . RANDOM +LOOP ; > > Here, we cannot test for equality. We have to test for crossing a > boundary instead, at least as far as I can see. > > With that in mi...

Ending a while loop inside a while loop
How do I make a while loop run as long as the while loop that contains it is running? I tried wiring both conditional terminals to a stop button in the outer loop, but that doesnt seem to work? Is there another way? &nbsp; Thanks. It doesn't work because of data dependency. Once you are inside the inner loop the outer loop will not go to the next iteration until the inner loop is done. It sounds to me like you want parallel loops running, rather than one inside the other. If you open the Example Finder (Help -&gt; Find Examples), and search for "loops", open the examples called "Stopping Parallel While Loops". One has a reset, and one doesn't. Message Edited by smercurio_fc on 04-22-2008 04:55 PM Hi Jasonalan, I am not sure what you are trying to implement, but it is true that the loops are not terminating because of data dependency. The stop button in the outer loop will not be read until the inner loop terminates.If you wish to terminate the two nested loops using a single stop button, you should read the stop button inside the inner loop and wire it to the conditional terminals in both the inner and outer loop. Again, there is no point in doing this unless you have some other logic along with the stop button to stop the loops. If only the stop button is being used to stop both the inner and outer loops, the outer loop will only execute once. In that case, you can just use a sequence structure followed by a single while loop. ...

what diference between timed loop and while loop and for loop
If I want to count 2 second working in the loop and next then going out of the loop I don't know&nbsp;which the loop &nbsp;I can use Message Edited by Jairak on 07-26-2008 03:14 PM Why do you need a loop to count for 2 seconds? To learn more about LabVIEW it is recommended that you go through the tutorial(s) and look over the material in the NI Developer Zone's <a href="http://zone.ni.com/devzone/cda/tut/p/id/5054" target="_blank">Learning Center</a> which provides links to other materials and other tutorials. You can also take the <a href="http://www.ni.com/academic/lv_training/how_learn_lv.htm" target="_blank">online courses</a> for free. Hi, &nbsp; From the information you have provided, I don't know exactly what you are trying to do. However, if you want a loop to iterate once, wait until two seconds and then exit the loop, use the "Wait Until Next ms Multiple" function, wire in a numeric constant "2000" and wire a boolean true constant to the loop condition of the while loop to iterate once, or use a for loop with "1" wired into the loop count. &nbsp; Perhaps you need to elaborate your question. Plus, check out the context help (press Ctrl + H) for a consice report on each of the loops. &nbsp; Regards, Jairak wrote: If I want to count 2 second working in the loop and next then going out of the loop I don't know&nbsp;which the loop ...

Nested FOR loops. (a loop within a loop)
I can't get my head around them. I have two MySQL tables, one contains the categories, the other contains the posts. Each post is linked to a category. Now I'm trying to display each post with a drop down menu that has the categories in it and have the category that the post is in selected. Here's my code for the drop down menu where my woes lie. for ($i=0; $i<count($posts); $i++) { for ($j=1; $j<=count($categories); $j++) { if ($j == $post[$i]['id']) { selected = ' selected="selected"'; } else { selected = ''; } $category_list .= '<option value="' . $j . '"' . $selected . '>' . $cat_name[$j] . '</option>'; } unset($j); $dropdown .= '<td><select name="' . $cat_name[$i]['name'] . '">'. $category_list . '</select></td>'; } Here's my problem, for ease, lets say I have 2 categories and 100 posts. For post one I have 2 categories in the menu. For the next post I have 4 categories in the menu (the 2 have been doubled), for the third I have 6 (tripled), and so on. Each post after the next has another 2 categories added. So the drop down menu for post 100 has 200 categories listed. Just the same two repeated over and over. The output should look like this, though an <option> for each category, but just two for this example....

Re: i am having a problem with while loops, i have two while loops, i have a random number generator inside the &quot;inside&quot; loop and i want to read an array outside the &quot;outer&quot; #2
Hi guys, Apologies about he messy thread - I needed asolution urgently and I didn't get a chance to notice the post date. &nbsp; :Ravens - Thank you a lot. The solution, also found in "my assignmnet live update.vi", works perfectly, doing exactly what I needed. Thanks again. kolorek ...

Nested parfor loop: Classification of Matrix inside loop
Hello, I am having problems with the following loop, since it is taking too much time. Hence, I would like to use parallel processing, specifically parfor function. Can anyone, please, help me to convert the following 'far' loop into 'parfor'? P = numel(scaleX); % quite BIG number sz = P; start = 1; sqrL = 10; % sqr len e = 200; A = false(sz, sz); parfor m = sz-sqrL/2:(-1)*sqrL:start for n = M(m):-sqrL:1 temp = [scaleX(m), scaleY(m); scaleX(n), scaleY(n)]; d = pdist(temp, 'euclidean'); if d < e A(m, n) = 1; end end end Thank you! "Bek Abdik" <beknazar@unist.ac.kr> writes: > I am having problems with the following loop, since it is taking too > much time. Hence, I would like to use parallel processing, > specifically parfor function. > > Can anyone, please, help me to convert the following 'far' loop into 'parfor'? > > P = numel(scaleX); % quite BIG number > sz = P; > start = 1; > sqrL = 10; % sqr len > e = 200; > A = false(sz, sz); > > parfor m = sz-sqrL/2:(-1)*sqrL:start > for n = M(m):-sqrL:1 > temp = [scaleX(m), scaleY(m); scaleX(n), scaleY(n)]; > d = pdist(temp, 'euclidean'); > if d < e > A(m, n) = 1; > end > end > end As the code analyzer message informs you, the range of a PARFOR l...

Error -50103 occured with timed loop inside a while loop
Hello everyone,i wrote an application to sample analog voltage from&nbsp; DAQ6024E card (see the attachments).I have a big while loop in the VI because a I want to add some other functions later.In the "WHILE_Cont Acq&amp;Graph Voltage-Int Clk.vi" I use a while loop inside the big while loop to read the samples. It's working properly. but when I use a timed loop inside the big while loop (see "TIMED_LOOP_Cont Acq&amp;Graph Voltage-Int Clk.vi"), I get an error -50103 from the timed loop.&nbsp; It seems that the first cycle is ok, but after the first cycle the error occurs. I don't know what happens with the timed loop, anyone can help me? what does the error -50103 mean? thanks a lot!PS: I am using LabVIEW 8.0Message Edited by molo511 on 10-22-2006 05:21 AMMessage Edited by molo511 on 10-22-2006 05:23 AM TIMED_LOOP_Cont Acq&Graph Voltage-Int Clk.vi: http://forums.ni.com/attachments/ni/170/211534/1/TIMED_LOOP_Cont Acq&Graph Voltage-Int Clk.vi WHILE_Cont Acq&Graph Voltage-Int Clk.vi: http://forums.ni.com/attachments/ni/170/211534/2/WHILE_Cont Acq&Graph Voltage-Int Clk.vi hi molo511, I tested your program but only with simulated devices. I had to delete the wire to the timing, so that the timed while loop runs with 1kHz. Did you already try this? Because this works on my PC. I also found a link in our database that might be interesting for you. &nbsp; <a href="http://digital.ni.com/public.nsf/websear...

nested loops only loop once
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another way I could write this to get both loops to complete fully? I am using the two while loops to pull data from different tables, and insert that data into a list that has html code surrounding each loop. while ($url = mysql_fetch_array($urls, MYSQL_ASSOC)) { $pn = $url['post_name']; while ($date = mysql_fetch_array($lmdate, MYSQL_ASSOC)) { $lm = $date['post_modified']; echo "<b>"; echo $pn; echo "</b>"; echo "more html"; echo date('Y-m-d', strtotime($lm)); echo "and more html"; } } Thank you. HG toddlahman@gmail.com wrote: > I am using two while loops that are nested. The first loop (post name) > returns the full column of results, but the second (post modified) > only returns the first row of the column. Is there another way I could > write this to get both loops to complete fully? > > I am using the two while loops to pull data from different tables, and > insert that data into a list that has html code surrounding each loop. > > while ($url = mysql_fetch_array($urls, MYSQL_ASSOC)) { > $pn = $url['post_name']; > > while ($date = mysql_fetch_array($lmdate, MYSQL_ASSOC)) { > $lm = $date['post_modified'...

How do I initialize one channel of a graph outside a loop, and the other channel INSIDE the loop
I am creating a test-control VI for a motor-control test bench.&nbsp; We have predefined load-cycles that we run depending on the article under test&nbsp;and attributes we wish to "stress".&nbsp; I&nbsp;load these profiles from a&nbsp;spreadsheet (txt file). &nbsp; I want to plot the load profile on a graph...and then, once testing has started, plot a second channel that consists of a single data point (filled to zero) that updates with every second of run-time.&nbsp; This second channel results ina vertical line drawn over the load profile indicating the current position.&nbsp; I run the test inside of a timed loop, and it works great once running. &nbsp; My problem is:&nbsp; Can I initialize the graph OUTSIDE of the timed-loop?&nbsp; I want to draw the test profile on the graph as soon as the operator loads it...which is long before I enter the timed-loop. &nbsp; ThanksMessage Edited by JeffGrimes on 09-03-2006 06:24 PM ...

Matlab parallel for loop or Matlab open pool
I am trying to to some computations and I would like to do it in parallel using parfor or by Opening the matlabpool.. as the current implementations is too slow: result=zeros(25,16000); for i = 1:length(vector1) % length is 25 for j = 1:length(vector2) % length is 16000 temp1 = vector1(i); temp2 = vector2(j); t1 = load(matfiles1(temp1).name) %load image1 from matfile1 t2 = load(matfiles2(temp2).name) % load image2 from matfile2 result(i,j)=t1.*t2 end end It work fine but I would really like to know if there is a way to speed thing up ... Thanks a lot in advance! ...

Improving loop speed with Timed Loop
Hey Everybody, &nbsp; I've got a little bit of an issue that I'm trying to work out: &nbsp; I have a timed loop comprised of 2 sequences.&nbsp; The first sequence measures the current position, compares that position to a position-velocity graph imported from excel, and then compares that commanded velocity to the current velocity to come up with a duty cycle to drive the motor at.&nbsp; The second sequence adjusts the duty cycle appropriately. &nbsp; Ideally, I'd like this to run as fast as possible within the 1Khz clock available (e.g 1ms dt -&gt; 1khz loop speed would be great!). &nbsp; However, when I run this, I find that the dt is actually around 65ms.&nbsp; (I adjusted up to 70ms, because I use the dt to infer velocity as the change in position/time, and wanted to give myself a margin of error). &nbsp; Is it possible to drastically speed this loop up?&nbsp; Are there any array allocations that I could do to make this run faster? &nbsp; I really appreciate any input you guys might have! Thanks! .jim PV_file.csv: http://forums.ni.com/attachments/ni/170/296815/1/PV_file.csv 8-DirControl_01222007.vi: http://forums.ni.com/attachments/ni/170/296815/2/8-DirControl_01222007.vi We can start with a few basic things and see how much they improve performance. Here are my first thoughts:- Why are there two frames in the Timed Loop? This really isn't necessary for anything. The main reason for using frames in a Timed L...

loops in parfor loops incredibly slow
Hi, I am currently debugging why my parallel application does not yield the expected speedup. I trimmed it down to the following minimal example, which results in a speed loss of about a factor of 12 when the outer loop is run as a parfor loop (runtimes 0.35s [for] compared to 4.4s [parfor] on my system, but you can easily scale this by means of the loop index limits): tic; for UnusedLoopIndex = 1 : 1e4 % switch this one between for and parfor for AnotherUnusedLoopIndex = 1 : 1e4, end end toc; I also have a slightly more complex example with a speedup loss of about 150, and a more practical one where I only observe a loss of 3 (depending on the loop body). I tried two setups: 1) parfor using the current MATLAB client (no matlabpool open, matlabpool('size') == 0) 2) parfor using one worker (matlabpool open 1, matlabpool('size') == 1) These give the same results (runtimes), both slower than for loops. Does anyone have a clue what is going on there? Do loops in parfor loops really pose problems? Note that replacing the inner loop by something like rand(30,30)*rand(30,30); does result in correct behavior, that is, equal runtimes for both for and parfor loops. Thanks Yannick I just got a helpful reply from the Mathworks support: The reason for this behavior is that the workers are not able to use the MATLAB accelerator on the plain parfor body, so the body is run as if "feature accel off" is set in the "for" loo...

Do Loop
To save me from checking generated machine code.... Does anyone know (for sure) if the following GoTo in a Do Loop in VB6 will cause any problems. I have programmed for 35 years, and have run into so many strange problems created by compilers, that I am always cautious. I can set a flag within the Do Loop and then "Exit Do" and check the flag outside the Do Loop, then branch if it is set. This is called over cautious, but it is always safe. The code generated by a Do Loop shouldn't care if there is a GoTo, but.... Anyway, keeping in mind that there is a better way to code this example, and that there is a serious coding problem and that this is JUST an example: i = 0 Do while This(i) <> That If This(i) = "What" Then GoTo SomewhereElse i = i + 1 Loop Thanks, Frank "Frank" <fnoell_cisi@hotmail.com> wrote in message news:113oslq1iifk188@corp.supernews.com... > To save me from checking generated machine code.... > > Does anyone know (for sure) if the following GoTo in a Do Loop in VB6 will > cause any problems. I have programmed for 35 years, and have run into so > many strange problems created by compilers, that I am always cautious. I > can > set a flag within the Do Loop and then "Exit Do" and check the flag > outside > the Do Loop, then branch if it is set. This is called over cautious, but > it > is always safe. The code generated by a Do Loo...

Looping
I have an SQL questions. I am trying to reset about 28 sequence generators with a looping program; my problem comes when I try to trim the prefix and suffix from the max number in the database. Currently I am using a left and right trim as follows. XXX = column name in this example I do know from looking at another table that controls the prefix and suffix that all prefix and suffix are alpha. RTRIM(ltrim(max(XXX),'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'ABCDEFGHIJKLMNOPQRSTUVWXYZ') any help would be great. On Feb 4, 10:47 pm, DPDesroc...@gmail.com wrote: > I have an SQL questions. > I am trying to reset about 28 sequence generators with a looping > program; my problem comes when I try to trim the prefix and suffix > from the max number in the database. > > Currently I am using a left and right trim as follows. XXX =3D column > name in this example I do know from looking at another table that > controls the prefix and suffix that all prefix and suffix are alpha. > RTRIM(ltrim(max(XXX),'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'ABCDEFGHIJKLMNOPQRSTU= VW=ADXYZ') > > any help would be great. Look up the TRANSLATE function in the SQL manual. Oracle9i SQL Reference Release 2 (9.2) Part Number A96540-02 >> The following statement returns a license number with the characters removed and the digits remaining: SELECT TRANSLATE('2KRW229', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789') &qu...

While loop
I need to work on the basics. source /export/home/myuser/main_proc_03 <---- My source file with all my procs. set testScript /var/tmp/passwd <------unix passwd file copies into temp location. set fi [open "$testScript" r] <------------- This opens and read all records into a file descriptor called $fi? while {![open $fi} { <--------------while it's NOT the end of $fi, it flows down. set k [gets $fi] <---------- gets the first line of $fi and assigns it to file descriptor $k if {[eof $fi]} {continue} <---------checks to see if some kind of file marker is at the end of $fi log_proc $k <---------called my proc that I've written located in source and passes the record in $k } <------------ends the while statement. Do I have this right? Also, where I have the {continue} what other options could I put in there? In article <8bd171ec-049f-4073-8034-a1a14cbf840f@v28g2000hsv.googlegroups.com>, progkcp <ken.parker.99@gmail.com> wrote: >I need to work on the basics. > >source /export/home/myuser/main_proc_03 <---- My source file with all >my procs. > >set testScript /var/tmp/passwd <------unix passwd file copies into >temp location. > >set fi [open "$testScript" r] <------------- This opens and read all >records into a file descriptor called $fi? > >while {![open $f...

DO+ ... LOOP
Hi, +LOOP is a nice feature for things like : : DOUBLING ( -- ) 32767 1 DO I . I +LOOP ; But is it wasteful for : : INC-COUNT ( step end start -- ) DO I . DUP +LOOP DROP ; (DUP inside that loop) ( From Starting Forth : http://home.iae.nl/users/mhx/sf6/sf6.html ) Is there a DO+ such that : : INC-COUNT ( step end start -- ) DO+ I . LOOP DROP ; (No DUP inside that loop) Thanks for your advice. PhiHo. "PhiHo Hoang" <phiho.hoang@rogers.com> writes DO+ ... LOOP [..] > +LOOP is a nice feature for things like : [..] > But is it wasteful for : > : INC-COUNT ( step end start -- ) > DO I . DUP +LOOP DROP > ; That depends on what you define as "wasteful," e.g., it is not necessarily "slower" or "larger." [1] mxForth server 0.04 (console), Jul 21 2003, 18:05:03. [2] Stuffed mxForth at 00404C30 [entry: 0x420000] [3] Current process priority is 32. mxForth vsn 3.3 FORTH> verbose off FORTH> : INC-COUNT1 ( times -- ) 0 DO I drop LOOP ; ok FORTH> : INC-COUNT4 ( times -- ) 4 * 0 DO I drop 4 +LOOP ; ok FORTH> : INC-COUNT4+ ( times -- ) 4 TUCK * 0 DO I drop DUP +LOOP DROP ; ok FORTH> : TEST ( -- ) <2>[FORTH>] CR ." inc-count1 = " TIMER-RESET #100000000 INC-COUNT1 .ELAPSED <2>[FORTH>] CR ." inc-count4 = " TIMER-RESET #100000000 INC-COUNT4 .ELAPS...

how to connect a start button to a for loop and control the loop
hi everyone, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I need a small help regarding the VI. VI has two "for loops" the VI should run in such a way that when the first loop ends I need to get a flash&nbsp; signal saying that the first loop had ended. Then i need a start button for the second loop so that I can start the loop when ever it is needed. I would be really thankful if any one can reply this thread thanks deepthi krishnamaneni Hi, &nbsp;&nbsp;&nbsp; This is not exactly the same but hope it serves your purpose. For Loops.vi: http://forums.ni.com/attachments/ni/170/152782/1/For Loops.vi Hi deepthi, &nbsp; take a look at this Vi too &nbsp; regards &nbsp; Dev &nbsp; 2 loop-events.vi: http://forums.ni.com/attachments/ni/170/152786/1/2 loop-events.vi hi everyone, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thanks a lot for your replies. I have gone through all the VI that you guys have sent. It was really helpful to me and learnt different ways of aproaching a single problem. That was interesting. Thanks once again deepthi krishnamaneni ...

for-loops that inherit the number of iterations from previous for-loops.
I am a newbie to Labview, and am trying to generate a hysteresis curve, that generates current that goes from 0 to +5, then down to -5, then all the way back up to +5 before returning back down to 0. Let's assume the current increments in steps of 1A. &nbsp; &nbsp; So, I have a flat sequence structure, containing 4 boxes, and within each I have one 'for' loop, one for each part of my curve. Each for loop needs to have a different number of iterations, let;s say, 5, 10, 10, and 5. &nbsp; But when I run this sequence, the first two always have 5 iterations (ie the same as the first for loop), the second 2 (usually) have 10 (ie the same as the 3rd for loop). Sometimes, they ALL will have 5 iterations! I have checked by wiring controls directly to N but this seems to have no effect on the number of iterations the loop will perform. The usual re-starting the computer and hardware doesn't work either :( &nbsp; I suppose it's possible to have 6 for-loops each with 5 iterations but this is not very elegant and I'm sure there is something wrong or that needs tweaking. &nbsp; Sorry about the long explanation and lack of VIs but they are all hooked up to hardware and on another computer. Sigh. &nbsp; Any help or just a pointer to documentation that would help would be greatly appreciated. ...

Loops
Hi, Hope someon can help. I am reading data in from a file , parsing it and reading values obtained into variables. In the following example only the first charcter of each line is being tested.It can either be an "X" a "Y" or a "Z". Dim a,b,c As String While NOT EOF(1) a = "" b= "" c= "" Line Input #1, INPUTLINE IF Mid(INPUTLINE,1,1) = "X" Then a = "X" IF Mid(INPUTLINE,1,1) = "Y" Then b = "Y" IF Mid(INPUTLINE,1,1) = "Z" Then c = "Z" wend The problem is if I use three message boxs to display the three values I get 9 iterations of the message boxes three containing the correct values and six blank values.There are only three lines in this input file example. I have tried all kinds of alternatives to prevent this but to no avail. I need just the three values so that I can pass them to a function.How do I get rid of the blank values?? Thanks in anticipation of a reply. Kevin "Kevin Robinson" <k.s.robinson@btinternet.com> wrote in message news:cmd0t7$h1i$1@titan.btinternet.com... > Hi, > Hope someon can help. > > I am reading data in from a file , parsing it and reading values obtained > into variables. > In the following example only the first charcter of each line is being > tested.It can either be an "X" a "Y" or a "Z". > > Dim a,b,c As String > While ...

while loop
Hi Guys, I would like to know if there is any possibility to send data out of a whileloop? in my attached snapshot I want to read out the number of iteration(loop count) when the program execute, but I can only see the result of last iteration that is normal while usinge a whileloop but is there any other possibility to see data toggling out of the while loop? &nbsp; Beni. while loop and indicator.jpg: http://forums.ni.com/attachments/ni/170/133660/1/while loop and indicator.jpg Hi, If I understand what you mean... You have a subvi with a whileloop inside. you connected the Iteration counter to an indicator So, in your top vi you get only the last iteration count. That is completely normal. The top vi gets the value of the indicator after the subvi completed his job. If you want the iteration counter to change while the loop is runing, you should use a&nbsp;reference to&nbsp;the indicator on your top vi and use a property node to change its value. &nbsp; Referencing.llb: http://forums.ni.com/attachments/ni/170/133681/1/Referencing.llb ...

Use a logic from for loop to stop do while loop outside
Hello, <br><br>It is a fairly simple logic however I don't know how to real= ize it in Labview. My program has two do-while loop with different iteratin= g rates. One is for data acquisition from hardware; the other loop is for d= ata logging. The data logging loop runs once per 60 sec (I don't need all t= he data), which is much slower than the 0.01sec time interval of the acquis= ition loop. I also need to minitor each sample acquired to be smaller than = a certain threashold. If there is one sample exceeding that limit the whole= acquisition process is considered to be malfunctioning and the data loggin= g loop should reset all the variables calculated from the previous data to = zero. And these zero values should be kept until a command is sent to react= ivate the logging process. In the mean time, the acquisition loop keeps run= ning.<br><br>I need to develop a logic in the acquisition loop to send out = a signal to the data logging loop. Note that 1000 samples are read from the= buffer per iteration in the do-while loop, and the comparation with limit = is performed in a 1000-time for-loop inside that iteration. I am new to Lab= view and not familiar with function vis. Can anyone give me any advice on t= his? Thank you. Hi. Welcome to the wonderful world of graphical dataflow programming. What = you're asking for is fairly general, so I'll suggest first that you take so= me LV tutorials, either on the web, or...

getting a value from a while loop to input back into the loop
This program is supposed to recognize an input voltage of 5V and then proceed to start&nbsp;the vertical bar picture box moving either left or right, per the users choice. The user can also input the desired bar width, scroll speed, and cycle duration (time to get from left to right and back). I want the picture box to move left and right repeately and smoothly. On frame #3, I created what I believe to be a state machine. The outer while loop should obtain the resulting position value from the inner while loop and then use that value as the new starting position. For some reason, the picture box will start moving left (if "Left" is chosen as the initial direction) and then remain on the left while shaking. It should rather move from the left back to the right and back left again. How do I fix this problem? Thank you!! &nbsp; (the first attachment is with the state machine. the second has the same problem as the first but has a less complicated format) &nbsp; vert rect with state machine.vi: http://forums.ni.com/attachments/ni/170/193862/1/vert rect with state machine.vi vert rect without state machine.vi: http://forums.ni.com/attachments/ni/170/193862/2/vert rect without state machine.vi I am unable to view your changes because I only have LabView 7.0. Could you post print screen images of your changes? Thank you so much! ...

Web resources about - while loop inside a for loop - comp.soft-sys.matlab

Inside Intercom
Brought to you by the team behind Intercom . We write about design, customer experience, start-ups, and the business of software.

Inside plant - Wikipedia, the free encyclopedia
... GR-513, Power Requirements in Telecommunications Plant (LSSGR Section 13) , contains detailed industry requirements for using power in an inside ...

Announcing Inside Social Apps NYC 2012
We’re excited to announce the first East-Coast edition of Inside Social Apps , happening in New York Dec. 3. This full-day conference will include ...

Tips for Error Free Writing and Twitter’s Tenth: Inside PR
Twitter turns ten. Four tips for good writing. And a legal decision that brings nothing good to anyone. This week, on Inside PR 437 , Gini Dietrich ...

Here's what it's like to fly inside 'The Residence,' the insanely luxurious private cabin that costs ...
... the plane, in a luxury "apartment" that retails for $6,500. Huang got it for $108 dollars and 60,000 AAdvantage miles, he says . Business Insider ...

Inside Donald Trump's bizarre Louisiana delegate fight
Inside Donald Trump's bizarre Louisiana delegate fight

Syrian experts shocked by damage inside Palmyra's museum
... Islamic State group, Syrian antiquities experts said Monday they were deeply shocked by the destruction the extremists had carried out inside ...

The Quantum Fluid Inside Neutron Stars
Supercooled helium acts very similar to the hot interior of a neutron star.

Easter celebration moved inside due to rain, snow
KANSAS CITY, Mo. — Weather was top of mind for parents who had Easter plans with their kids. One of Kansas City’s biggest Easter events came ...

Inside the ExoMars mission
Inside the ExoMars mission

Resources last updated: 3/30/2016 1:56:54 PM