Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to get a Matlab <-> C++ interface [closed]

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

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.

like image 910
fpdragon Avatar asked Jun 28 '11 12:06

fpdragon


People also ask

How do I force close MATLAB?

Click the close button on the MATLAB® desktop. Click. on the left side of the desktop title bar and select Close. Type quit or exit at the command prompt.

How do you end a process in MATLAB?

To stop execution of a MATLAB® command, press Ctrl+C or Ctrl+Break. On Apple Macintosh platforms, you also can use Command+. (the Command key and the period key).

Is MATLAB close to C++?

Much more. Matlab is an abbreviation of C++ is an object-oriented as Matrix Laboratory, which is a well as a general-purpose high-performance language. programming language. Scientists and engineers use it for technical computing in 2D and 3D form.


1 Answers

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')");

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

like image 104
Chris Avatar answered Oct 13 '22 01:10

Chris