Discussion:
Using Java Timer in Matlab
(too old to reply)
Marco
2010-02-26 14:38:04 UTC
Permalink
I'd like to use a Java Timer (util.java.Timer) instead of matlab timer object. My only problem is that Java Timer Class need to define a TimerTask derived class with the proper run() method. How can i invoke Matlab code in the run method?

Thanks in advice for any useful information
Yair Altman
2010-02-27 18:19:04 UTC
Permalink
Post by Marco
I'd like to use a Java Timer (util.java.Timer) instead of matlab timer object. My only problem is that Java Timer Class need to define a TimerTask derived class with the proper run() method. How can i invoke Matlab code in the run method?
Thanks in advice for any useful information
You'll need to use JMI to call Matlab from Java. Note however, that JMI needs to wait for the main Matlab computational thread, so the benefits of using a Java thread may be diminished.

Yair Altman
http://UndocumentedMatlab.com
Yair Altman
2010-02-28 17:59:06 UTC
Permalink
Post by Yair Altman
Post by Marco
I'd like to use a Java Timer (util.java.Timer) instead of matlab timer object. My only problem is that Java Timer Class need to define a TimerTask derived class with the proper run() method. How can i invoke Matlab code in the run method?
Thanks in advice for any useful information
You'll need to use JMI to call Matlab from Java. Note however, that JMI needs to wait for the main Matlab computational thread, so the benefits of using a Java thread may be diminished.
Yair Altman
http://UndocumentedMatlab.com
I just though of a neat hack that would bypass the need for JMI: in your Java run() code, simply raise an event (see http://www.mathworks.com/matlabcentral/newsreader/view_thread/272321 for sample code) on a Java object that is loaded in Matlab. In Matlab, listen on this event using a simple callback or a handle.listener. Then the corresponding Matlab callback code would be invoked when the Java run() is encountered.

Yair Altman
http://UndocumentedMatlab.com

Loading...