How to execute 2 functions simultaneously in the same loop on a GUI

조회 수: 1 (최근 30일)
Adam Taher
Adam Taher 2015년 5월 29일
댓글: Salaheddin Hosseinzadeh 2015년 5월 29일
I have a program that uses DAQ to generate signals. I have a timer that runs between a specific range. But I want the timer to keep running even if the signal is generating. What I mean, is that the code that generates the signal has its own time... So when the period of generation is done, my timer restarts where it was.
Example: while(something) time = time + 1; pause(1);
if time == 1 generate signal code (for 5 seconds); end; end;
after generating is finished, time = 2, =3, etc. But I want time to keep running while generating signal.
Any idea? should I use global, persistent variable for time?
  댓글 수: 3
Adam Taher
Adam Taher 2015년 5월 29일
편집: Adam Taher 2015년 5월 29일
Hi,
My code is something like: (i'm using GUI)
handles.time = 0;
while(something)
handles.time = handles.time + 1; pause(1); % this will make my counter increment every 1 second.
if handles.time == 5
display('generating');
Generation signal code over here (this code has its own period of time)
end; end;
So what happens is when time == 5, the generation code executes, but my handles.time stops counting, it doesn't keep running, which I understand why. It restarts counting AFTER that the generation code finishes. But what I want, is that handles.time is able to keep running WHILE the generation code is executing.
So I was wondering if there is a function that could help.
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh 2015년 5월 29일
Ok Adam, that's a bit better now!
Generally that's not a good way of keeping the track of time. you can make the while loop running. you can either make a timer object, or even make it easier and use tic toc commands
tic
toc
Anyhow, tic toc will keep the track of time for you while another code is running ;)
Good luck!

댓글을 달려면 로그인하십시오.

답변 (1개)

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh 2015년 5월 29일
Ok Adam, that's a bit better now!
Generally that's not a good way of keeping the track of time. you can make the while loop running. you can either make a timer object, or even make it easier and use tic toc commands
tic
toc
Anyhow, tic toc will keep the track of time for you while another code is running ;)
Good luck!

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by