I have converted a piece of code to C++ using Matlab and now have them in MSVC++.
My function: myFunction gets two inputs and has one output. Following, I tried to make the inputs, a, b, and allocate the output, but I got this error: error C3861: 'emxCreate_real_T': identifier not found
The function prototype looks like this, which in essence is C = A + B:
#include "myTestFunction.h"
#include "myTestFunction_emxutil.h"
void myTestFunction(const emxArray_real_T *A, const emxArray_real_T *B,
emxArray_real_T *C)
{
int i0;
int loop_ub;
i0 = C->size[0] * C->size[1];
C->size[0] = A->size[0];
C->size[1] = A->size[1];
emxEnsureCapacity((emxArray__common *)C, i0, (int)sizeof(double));
loop_ub = A->size[0] * A->size[1];
for (i0 = 0; i0 < loop_ub; i0++) {
C->data[i0] = A->data[i0] + B->data[i0];
}
}
and here is my main function:
int main() {
double a[3][3];
double b[2][2];
double result[4][4] = {};
emxArray_real_T *inpA, *inpB, *outp;
// define input matrix
double p = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++){
a[i][j] = p;
p = p + 1;
}
}
double k = 0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
b[i][j] = k;
k = k + 1;
}
}
inpA = emxCreateWrapper_real_T(*a, 3, 3);
inpB = emxCreateWrapper_real_T(*b, 2, 2);
outp = emxCreateWrapper_real_T(*result, 4, 4);
//inpA = emxCreate_real_T(a, 3, 3);
//inpB = emxCreate_real_T(b, 2, 2);
//outp = emxCreate_real_T(result, 4, 4);
myTestFunction(inpA, inpB, outp);
//print result
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++)
cout << outp[i].data[j] << endl;
}
return 0;
}
How should I declare the inputs and output?