From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

while loop inside control & simulation loop

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

0 Kudos
Message 1 of 4
(4,022 Views)

Hi MarcoAlmeida,

 

Did you try step by step debugging ?

If yes, what happen inside your while loop ?

 

Regards

0 Kudos
Message 2 of 4
(3,981 Views)

Hello ThibaultP,

 

No I didnt try. I'll do it and come back to say what happen.

Thanks.

 

 

0 Kudos
Message 3 of 4
(3,957 Views)

Hi again.

 

I tried to do it but it seems to be dificult to me to understand what is going on inside loop because Vi is too big with multiples sub-vi's.

 

I got another way to do what I want.

Thanks anyway.

 

I have another problem reading excel files: my simulation gets too low but I'll try to do a search for same problem in another topic.

Regards

Marco

0 Kudos
Message 4 of 4
(3,908 Views)