-
Notifications
You must be signed in to change notification settings - Fork 0
/
libEDM_matlab.cpp
74 lines (57 loc) · 1.75 KB
/
libEDM_matlab.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <libEDM_library.h>
#include <libEDM_matlab.h>
using std::cerr;
using std::endl;
MATLAB matlab;
cVector convert_mxType (const mxArray *input)
{
cVector output(mxGetNumberOfElements(input));
double *inputReal = mxGetPr(input);
double *inputImag = mxGetPi(input);
for (size_t index = 0; index < output.size(); index++)
output[index] = complex<double>(inputReal[index], inputImag[index]);
return output;
}
mxArray* convert_mxType (const cVector &input)
{
mxArray *output = mxCreateDoubleMatrix(input.size(), 1, mxCOMPLEX);
double *outputReal = mxGetPr(output);
double *outputImag = mxGetPi(output);
for (size_t index = 0; index < input.size(); index++)
{
outputReal[index] = input[index].real();
outputImag[index] = input[index].imag();
}
return output;
}
mxArray* convert_mxType (const cMatrix &input)
{
mxArray *output = mxCreateDoubleMatrix(input.rows(), input.cols(), mxCOMPLEX);
double *outputReal = mxGetPr(output);
double *outputImag = mxGetPi(output);
for (size_t col = 0; col < input.cols(); col++)
for (size_t row = 0; row < input.rows(); row++)
{
*outputReal++ = input[row][col].real();
*outputImag++ = input[row][col].imag();
}
return output;
}
Engine *MATLAB::engine = NULL;
void MATLAB::openEngine ()
{
// Open engine if not already open
if ( !engine )
engine = engOpen(NULL);
// Abort if cannot open engine
if ( !engine )
error("Cannot open MATLAB engine");
// Hide MATLAB engine
engSetVisible(engine, false);
}
MATLAB::~MATLAB ()
{
if ( engine )
engClose(engine);
}