使用来自C ++可执行文件的输入数据在MATLAB中进行数据流传输 [英] Data streaming in MATLAB with input data coming in from a C++ executable

查看:193
本文介绍了使用来自C ++可执行文件的输入数据在MATLAB中进行数据流传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对MATLAB完全陌生,我想知道从C ++文件进行数据流传输的选择.

I'm completely new to MATLAB and I want to know what my options are for data streaming from a C++ file.

我听说过为此目的使用MATLAB引擎",以及诸如engPutVariable之类的一些方法,但是有人可以给我一个详尽的例子来说明如何实现它吗?我正在尝试实现正弦波流传输,但是通过一个简单的示例数据集发送就足够了.

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.

推荐答案

您有两个选择:matlab引擎和mex函数.请务必注意,Matlab API是单线程的.绝对没有办法让用户可见的后台线程.充其量是,UI事件会中断.

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.

使用Matlab引擎,您的应用程序是一个使用Matlab作为外接程序库的C ++应用程序.您可以从C ++调用Matlab函数,但必须确保在任何时间点只有一个线程访问Matlab.因此,您可能拥有一个线程,该线程将来自应用程序其余部分的输入队列中的数据馈送到Matlab. C ++可以具有任意数量的线程,但是只有一个线程可以与Matlab交互.

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.

另一种方法是让Matlab控制主应用程序,并在需要更多数据时调用C ++代码. C ++代码充当Matlab的插件. C ++代码可以具有所需的任意多个线程,但是Matlab在您的m文件调用它时会轮询C ++.查找有关MEX功能的文档.

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.

这篇关于使用来自C ++可执行文件的输入数据在MATLAB中进行数据流传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆