Hello, My target is to create a time-object which will check every 10 minutes if Matlab is used. Do you have any ideas how to do it? I know how to create time object and how to use startup.m, finish.m scripts, but how can I verify if Matlab is running (and really in use) or it is just minimalized or covered by another window when user does something else?
Best regards, Pawel

4 件のコメント

per isakson
per isakson 2014 年 1 月 27 日
You want to this from inside the matlab session? An alternative would be to have a separate "program" to monitor the matlab session.
Pawel Blaszczyk
Pawel Blaszczyk 2014 年 1 月 27 日
I would rather do it in Matlab by itself, but using external app is also an option. I am pretty sure it can be realized in C# but I have no experience with that so I focused on Matlab :-) I thought about java objects - maybe this is an option...
Walter Roberson
Walter Roberson 2014 年 1 月 27 日
Which operating system?
Pawel Blaszczyk
Pawel Blaszczyk 2014 年 1 月 28 日
Window$ 7

サインインしてコメントする。

 採用された回答

per isakson
per isakson 2014 年 1 月 27 日
編集済み: per isakson 2014 年 1 月 28 日

0 投票

I guess you use Windows
  • download PsList (better than tasklist)
  • the timer callback function shall call pslist.exe
% pslist.exe shall be in the same folder as this function
dos_fmt = [ fullfile( fileparts( which( mfilename ) ), 'pslist.exe' ), ' %s' ];
dos_fmt = strrep( dos_fmt, '\', '\\' );
dos_cmd = sprintf( dos_fmt, num2str(val) ); % num2str takes strings
mlb_cmd = sprintf( 'dos( ''%s'' );', dos_cmd );
dos_buf = evalc( mlb_cmd );
where val is equal to 'matlab' (or it's ProcessID)
Compare the current CPU Time and Elapsed Time with the previous ones.
An alternative is JavaScript in combination with the windows script host, wscript

6 件のコメント

Walter Roberson
Walter Roberson 2014 年 1 月 28 日
A further point: someone indicated recently (in a discussion about pslist) that when a MATLAB figure is minimized, there is no MS Windows-level frame for it, that the frame is not just hidden but actually non-existent. I might easily have the details wrong as I saw it in passing.
Pawel Blaszczyk
Pawel Blaszczyk 2014 年 1 月 28 日
Thanks! I will check this solution asap
per isakson
per isakson 2014 年 1 月 28 日
編集済み: per isakson 2014 年 1 月 28 日
Walter, I made a little test
  • Started Matlab
  • plot(magic(5),'d')
  • minimized the two windows interactively; clicked the button in the top right corner
  • run pslist matlab at the cmd-prompt
Result:
H:\m\test4ida\lib>pslist matlab
pslist v1.3 - Sysinternals PsList
Copyright (C) 2000-2012 Mark Russinovich
Sysinternals - www.sysinternals.com
Process information for KTH-2957:
Name Pid Pri Thd Hnd Priv CPU Time Elapsed Time
MATLAB 7988 8 89 1697 687300 0:00:55.832 0:05:14.059
This is what I expected, i.e. process information on Matlab itself. There is no information on the plot-window. This is close to the information displayed by Windows Task Manager, Processes.
Pawel Blaszczyk
Pawel Blaszczyk 2014 年 1 月 28 日
編集済み: Pawel Blaszczyk 2014 年 1 月 28 日
This function doesn't show how much window was focused only how much CPU was used by Matlab i.e. if you run simulation and minimalize ML counter will be still running. However it showed me that using external *.exe file will be the easiest way
Walter Roberson
Walter Roberson 2014 年 1 月 28 日
Sorry I do not seem to be able to find the discussion that I recently saw. I seldom use MS Windows so I do not know the particular jargon that would have to be used for the query.
Sort of relevant to the overall task:
per isakson
per isakson 2014 年 1 月 28 日
編集済み: per isakson 2014 年 1 月 28 日
Pawel, this question at Stackoverflow might help you get started How can I tell if a Window has focus? (Win32 API). See also the Linked and Related questions.
I use the approach I proposed to determine if a process has finished working; isn't using more cpu-cycles.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索

質問済み:

2014 年 1 月 27 日

編集済み:

2014 年 1 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by