Let Matlab continue without waiting for a result

后端 未结 1 1470
栀梦
栀梦 2021-01-19 15:50

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 fu

相关标签:
1条回答
  • 2021-01-19 15:55

    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).

    0 讨论(0)
提交回复
热议问题