필터 지우기
필터 지우기

How to run a MATLAB program for a specified time duration?

조회 수: 4 (최근 30일)
RZM
RZM 2016년 5월 17일
댓글: Guillaume 2019년 8월 21일
For example if there is a MATLAB program as follows:
duration = 1 % minute
i=1
while i<1000
[X,Y] = ginput(1)
i = i+1;
end
Is there any way to terminate the execution of this program or getting out of the loop when it reaches to the assigned amount of time (1 minute in this case) in such a situation in which continuation of the loop needs the user intervention (in this case clicking on any point on the plotted figure)?
  댓글 수: 2
somayehRazaghi
somayehRazaghi 2019년 8월 21일
hi
i have the same problem. i want to execute a function just for a specified time (like t). for example:
t=5; % in second
[Sensors,Receiver]=FindReceiver3(Sensors,Network,sender);
if (Receiver==0 ) && t==5)
disp('must change channel');
end
how can i do this?
Guillaume
Guillaume 2019년 8월 21일
This is very different from what was asked here, so please start your own question.

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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 5월 17일
No. The closest you can get is to sometimes be able to quit the entire MATLAB session when a timer expires. However, if the MATLAB session is deep into calculations, then the only way to interrupt it is to ask your operating system to kill the process.
  댓글 수: 2
RZM
RZM 2016년 5월 17일
Thanks Walter, So if it is not possible, one way could be using callback functions instead of using loops, but can the callback function see whether it is time to end running the script?
Walter Roberson
Walter Roberson 2016년 5월 17일
Your problem is the ginput(): you can't interrupt it when the time expires.
If you recode the ginput() in terms of getting the current point when a ButtonDownFcn is detected, then that can be put into a callback, and you can do the kind of loop until toc that is discussed above; just make sure you have a pause() to allow the button event to run.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by