Pass command to engEvalString() and return immediately

When using engEvalString from my programs it is not always necessary to wait for the MATLAB console to send back a response (i.e. the prompt '>>' ). Is it possible to tell the engine to execute my commands asynchronously?
Example: My program emits "plot(x,y);" when a window is already open but has to wait seconds before the plot finishes and the MATLAB prompt returns.
An experiment with engOutputBuffer, setting the buffer size to 0, didn't work as hoped. It is understandable that returning immediately might be a bad idea when the application keeps sending commands without pause but maybe there is special non- blocking engine call that I can try?
It is of course possible to setup a parallel thread in my code to do the waiting but it feels like overkill.

3 comentarios

dpb
dpb el 16 de Mzo. de 2026 a las 16:39
Editada: dpb el 16 de Mzo. de 2026 a las 18:24
I'm not sure there is anything other than another thread to not block the executing thread when it is time to refresh the image. However, rather than calling the high level plot() function again on an existing plot, you might find setting the XData, YData arrays directly more responsive -- but, then again, maybe not if it's actually redrawing the image that is the bottleneck.
Depending upon what you're actually changing, you might find switching to the animatedline helpful.
marcel hendrix
marcel hendrix el 16 de Mzo. de 2026 a las 18:53
Interesting, but my example of plotting is just that: an example.
Another possibility is to write some kind of GUI gadget in MATLAB that picks up queued commands from my application and executes them asynchronously. But such a loop looks suspiciously like what a comserver is supposed to do already?
dpb
dpb el 16 de Mzo. de 2026 a las 20:39
Editada: dpb el 17 de Mzo. de 2026 a las 16:34
I think that will all depend upon how the COM server is configured internally...it will do what it is told to do, however long that might take. If it knows the graphics are being updated and the command prompt doesn't come back until after in an interactive session, I don't think it will behave any differently to the caller from afar...the internal engine doesn't know any different from the two.
MATLAB doesn't implement an asynch COM server model -- here's a blog from MS on what one would do if were writing one for background info.
AI Bot returned the following...
If you need non-blocking behavior, you must handle the asynchrony at the client level or use a different MATLAB interface:
  1. Client-Side Threading: Run the COM calls on a background thread within your client application (e.g., using Task.Run in C# or a worker thread in C++). This keeps your UI responsive while the background thread waits for the synchronous COM call to return.
  2. MATLAB Engine for Python/C++: Modern alternatives like the MATLAB Engine API explicitly support asynchronous calls (e.g., using the background=True argument) and return "future" objects.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Productos

Versión

R2023a

Preguntada:

el 16 de Mzo. de 2026 a las 15:55

Editada:

dpb
el 17 de Mzo. de 2026 a las 16:34

Community Treasure Hunt

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

Start Hunting!

Translated by