Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Let Matlab continue without waiting for a result

Tags:

matlab

I have the following question: How do I tell Matlab that it should not wait for the results of a function? Is there a way other than threads?

My problem: I have a function A that is called by a Timer every few seconds. If a specific event is met, another function B is called inside function A. Function B opens a Batch File. I want function A to go on without waiting for function B to end. Is there a way to easily do it?

I'm sorry if this question was already asked, but I couldn't find a satisfying answer. Please also excuse my bad english.

I would like to thank everyone who answers for their help.

like image 866
Nikster Avatar asked Sep 29 '22 14:09

Nikster


1 Answers

In your function B, just call the batch file with a & at the end of the line.

For example:

!mybatch.bat &

This will run the file mybatch.bat in background mode and will return execution to Matlab immediately after the call.

or if you prefer the complete form:

[status, result] = system('mybatch.bat &')

But in this case it is a bit useless, since the system call mybatch in the background, the result variable is always empty and status is always 0 (whether a file mybatch.bat was found and executed or not)


edit: That is the quick trick in case it is only the batch file execution which is slowing down your program.

If you have more matlab instructions in function B and you really need function A to go on without waiting, you will have to set up a listener object with function B as a callback. Then in your function A, trigger the event (which will activate the listener and call function B).

like image 98
Hoki Avatar answered Oct 04 '22 03:10

Hoki