Quantcast
Channel: Counter/Timer topics
Viewing all articles
Browse latest Browse all 1271

while loop inside control & simulation loop

$
0
0

Hi all,

 

I have a problem when using while loop inside mathscipt used inside control & simulation loop.

 

I want to read a excel cell each 5 seconds and to do it I'm using matlab scrip to know when I have to change cell.

 

My inputs on mathscipt are: run_time and sim_time. 1st one is the running time from control & simulation loop and 2nd is the time of each simulation.

My output is cell to go to the VI excel reader.

 

So, to do it I'm using a while loop like this:

 

cell=H1;                                       % starting on excel cell H1

count=1;                                       % creating and starting counter variable

h=5;                                               % creating and starting second counter

 

while run_time < sim_time do   % while loop: do it until reach simulation time.

 

if run_time ==h                             % compare running time with next 5 second (5,10,15,20,...)

count = count +1;                         % increase counter for next 5sec

h=h*count;                                     % to compare on "if" next loop (5+5, 10+5, 15+5,....)

cell=strcat('H',int2str(count));     % put on ouput next cell: H2,H3...

end

 

end

 

But, when I used while loop it doesn't do nothing. My code is working without while loop, but it only does 2 cells. I want more than that.

 

Is there anyone can help me with it? another way to do it?

 

Thanks in advance.

 

Regards.

Marco


Viewing all articles
Browse latest Browse all 1271

Trending Articles