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

dpb
dpb 2026년 3월 16일 16:39
편집: dpb 2026년 3월 16일 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.
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 2026년 3월 16일 20:39
편집: dpb 2026년 3월 17일 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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 COM Component Integration에 대해 자세히 알아보기

제품

릴리스

R2023a

질문:

2026년 3월 16일 15:55

편집:

dpb
2026년 3월 17일 16:34

Community Treasure Hunt

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

Start Hunting!

Translated by