最好的方法来获得一个Matlab< - > C ++接口 [英] Best way to get a Matlab <-> C++ interface

查看:114
本文介绍了最好的方法来获得一个Matlab< - > C ++接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++ Windows程序,我想在现有的Matlab程序中转换和可视化来自这个C ++应用程序的一些数据。

I have a C++ Windows Program and I want to convert and visualize some data from this C++ app in an existing Matlab Program.

目前我正在写数据将C ++应用程序转换为文件。同时,Matlab应用程序读取文件并处理数据。 (poll)它基本上可以工作,但是当数据负载变高时,我遇到性能问题。

Currently I am writing the data from the C++ app into files. At the same time the Matlab app reads the files and processes the data. (polling) It basically works but I am running in performance troubles when the data load gets to high.

在这些程序之间传输数据的最佳解决方案是什么?我在想一种消息队列或套接字接口。

What is the best solution to transfer data between this programs? I am thinking of a kind of message queue or socket interface.

推荐答案

使用Matlab API 将数据从C ++发送到Matlab,然后对其执行plot命令。
粗略地,执行以下操作 - 没有错误检查,但是gist是存在的:

Use the Matlab API to send your data from C++ to Matlab, then execute a plot command on it. Roughly, do the following -- there are no error checks, but the gist is there:

#include <engine.h>
//open the engine
Engine *m_engine;
m_engine = engOpen("\0");

//put our data
//pretend this is a 2 column, n row matrix, so we can do a 2D plot
mxArray* mx = mxCreateDoubleMatrix(mat->n_rows, mat->n_cols, mxREAL);
memcpy(mxGetPr(mx),some_data,data->n_elem*sizeof(double));
put("data",mx);
mxDestroyArray(mx);

//plot
engEvalString(m_engine, "plot(data(:,1),data(:,2),'-o')");

请记住,Matlab在专栏中工作,而C ++是行专业。

Just remember, Matlab works in column major, while C++ is row major.

这篇关于最好的方法来获得一个Matlab&lt; - &gt; C ++接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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