Is it possible to tell when Matlab is busy executing?

조회 수: 57 (최근 30일)
Jim Hokanson
Jim Hokanson 2015년 6월 13일
편집: Tien 2024년 4월 7일
Is it possible to tell when Matlab is busy executing? I'd like to run some code on a timer but I'd rather not execute the main portion of the function if Matlab is currently executing other code (besides other timers or GUI functions).
Thanks, Jim
  댓글 수: 3
Walter Roberson
Walter Roberson 2015년 6월 13일
I think the point is to determine by code whether MATLAB is busy.
Jim Hokanson
Jim Hokanson 2015년 6월 13일
Walter is correct, although if no other option were present, looking for the absence of >> would be a decent hack that is possible to do by code. Fortunately I think Jan's approach will work much better.

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

채택된 답변

Jan
Jan 2015년 6월 13일
isBusy = CmdWinTool('isBusy')
If a program is running, the command window's status text is set to 'Busy'. This does not happen inside a callback of a timer object. So this status text can be used to determine if Matlab is busy.
CmdWinTool assumes, that Matlab is busy, when the status text is not empty. This happens also, if you stop during the debugging.
  댓글 수: 2
Jim Hokanson
Jim Hokanson 2015년 6월 13일
Great. Thanks!
I actually want my code to be running while debugging. Is there any reason why you are avoiding looking for 'Busy'?
Jan
Jan 2015년 6월 13일
An active timer callback might be very confusing during debugging. When Matlab stops in a line I expect that the internal state freezes. But you can replace CmdWinToll('isBusy') by:
~strcmpi(CmdWinTool('statusText'), 'Busy')

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

추가 답변 (2개)

DZ
DZ 2021년 11월 1일
One way I insert a bit of "meta" info on the status of a Matlab instance is via the Window title.
To set the title of the running Matlab instance,
com.mathworks.mlservices.MatlabDesktopServices.getDesktop.getMainFrame.setTitle()
To retrieve the title of the running Matlab instance,
com.mathworks.mlservices.MatlabDesktopServices.getDesktop.getMainFrame.getTitle()
So at the start of any function, you can insert a phrase such as '[High Priority]' for the function that you don't want interrupted. I also like to include the PID for general debugging purpose. At the end any function in your library, search for and remove the tag and maybe insert a tag like '[Task Complete]', which makes an idling Matlab instance easier to spot visually in Windows. Functions below may be of help:
contains()
erase()
feature('getpid')
In your timer triggered function, you can simply check for tag in the window title before proceeding to the rest of the function.
Now, the timer triggered function will still interrupt any running function for a brief moment. So you may want to include a component of your code that handles timer interruption -- whether the control is handed back immediately or after your timer triggered function actually ran for a while.

Tien
Tien 2024년 4월 7일
편집: Tien 2024년 4월 7일
I try to calculateIntraScore Hyperspectral raw file and it's busy for a long time :((
I do not know what is MATLAB doing?

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by