I'm completely new to MATLAB and I want to know what my options are for data streaming from a C++ file.
I heard of using the MATLAB "engine" for this purpose, and some of the methods like engPutVariable, etc., but can someone give me a thorough example of how to go about doing it? I'm trying to implement streaming a sine wave, but a simple example of sending a sample set of data through should suffice.
You have two options: the matlab engine and mex functions. It's very important to note that the Matlab API is single-threaded. There is absolutely no way to have user-visible background threads. At best, there are interrupts for UI events.
With the Matlab engine, your application is a C++ application that uses Matlab as an add-in library. You can call Matlab functions from C++, but you must make sure that only one thread accesses Matlab at any point in time. So, you could have a thread that feeds data to Matlab from a queue of inputs coming from the rest of your application. The C++ can have as many threads as it wants, but only one can interact with Matlab.
The other approach is to have Matlab control the main application and have it call C++ code whenever it wants some more data. The C++ code acts as a plugin for Matlab. The C++ code can have as many threads as it wants, but Matlab polls the C++ when your m-file calls it. Look up the documentation on MEX functions.
来源:https://stackoverflow.com/questions/1071778/data-streaming-in-matlab-with-input-data-coming-in-from-a-c-executable