MATLAB 中的数据流,输入数据来自 C++ 可执行文件
我对 MATLAB 完全陌生,我想知道从 C++ 文件传输数据有哪些选项。
我听说过使用 MATLAB“引擎”来实现此目的,以及一些方法,例如 engPutVariable 等,但是有人可以给我一个完整的示例来说明如何去做吗? 我正在尝试实现正弦波流,但发送一组样本数据的简单示例就足够了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有两个选择:matlab 引擎和 mex 函数。 值得注意的是,Matlab API 是单线程的。 绝对没有办法拥有用户可见的后台线程。 最好的情况是,UI 事件会出现中断。
有了 Matlab 引擎,您的应用程序就是一个使用 Matlab 作为插件库的 C++ 应用程序。 您可以从 C++ 调用 Matlab 函数,但必须确保在任何时间点只有一个线程访问 Matlab。 因此,您可以有一个线程,将来自应用程序其余部分的输入队列中的数据提供给 Matlab。 C++ 可以有任意多的线程,但只有一个线程可以与 Matlab 交互。
另一种方法是让 Matlab 控制主应用程序,并在需要更多数据时调用 C++ 代码。 C++ 代码充当 Matlab 的插件。 C++ 代码可以拥有任意数量的线程,但是当您的 m 文件调用 C++ 时,Matlab 会轮询它。 查找有关 MEX 函数的文档。
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.