I am using R2019b version of Matlab and integrating the Matlab engine API into legacy C code using MS VS 2008 (compiled to 64 bit). When issuing a Matlab command to run a program using the engEvalString(..) command I found that the command is blocking (synchronous) in the C code, example:
engEvalString(ep,"my_m_code");
or
engEvalString(ep,"pause(10)");
Is there a way to issue an asynchronous Matlab command from C so that it is non-blocking on the C code side? Or is there a way to start the Matlab engine from C code so that it runs asynchronously.
The C code passes Numeric Matrix data to matlab using the function engPutVariable(..) and it (C code) is very time sensitive in it's task and can only be minimaly blocked by Matlab's process.
Thanks for your input

댓글 수: 3

Mohammad Sami
Mohammad Sami 2020년 1월 3일
편집: Mohammad Sami 2020년 1월 3일
It seems that calling Matlab from C++ can be done asynchronously. Do you have the option to use C++ ?
Otherwise you would have to implement your own system in C. Perhaps you have two threads. One thread talks to Matlab and the other runs your program. You can have a queue in place to send jobs to Matlab.
Note call to matlab C engine are not thread safe, so only one thread should talk to matlab.
JimTal
JimTal 2020년 1월 3일
I was able to compile the legacy C code in C++ (VS 2008) but as per my understanding I need to use the Matlab library libMatlabEngine.lib which requires c++ 11 to create async calls to Matlab from C++ (maybe I'm wrong here). Unfortunately I've NOT been able to find an example.
The approach of using multi threads and a queue in C is appealing but again I've not been able to find an example. If you have knowledge of sample code which could help I would grestly appreciate it.
Mohammad Sami
Mohammad Sami 2020년 1월 7일
Yes I think Matlab currently requires minimum VS 2015. I don't have any examples available.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Call MATLAB from C에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2020년 1월 2일

댓글:

2020년 1월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by