Can MATLAB use a MEX Function that run continuously?
Show older comments
I have a socketing program writtne in C++ which runs continously and I'm trying to use MATLAB to plot the data. I looked into MEX functions but all the examples are of functions that execute and return a single value. Is there a way to continuously feed data from C++ into MATLAB and produce live graphs?
3 Comments
Walter Roberson
on 13 Nov 2018
perhaps invert the flow?
https://www.mathworks.com/help/matlab/calling-matlab-engine-from-c-programs-1.html
NaiveMeasurement
on 13 Nov 2018
Walter Roberson
on 13 Nov 2018
MATLAB uses a single main execution thread unless you use the Parallel Computing Toolbox. When you call into .mex then nothing in the main MATLAB engine can get done, including not processing any graphics that has not been handed over to the graphics thread already. Even timers cannot execute.
So if you infinite loop in mex doing data collection, then you cannot process the data on the MATLAB side.
It is valid to collect multiple values before returning, and there is always a trade off between waiting collecting values efficiently and returning for more processing, against function call overhead every time you go back for more data: the less data you collect the faster you can react to each datum but the more overhead in the collecting.
Accepted Answer
More Answers (0)
Categories
Find more on Call C++ from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!