在C ++中处理emxArray_real_T数据 [英] dealing with emxArray_real_T data in C++

查看:1092
本文介绍了在C ++中处理emxArray_real_T数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Matlab将一段代码转换为C ++,现在将它们转换为MSVC ++.

I have converted a piece of code to C++ using Matlab and now have them in MSVC++.

我的功能:myFunction获得两个输入,但只有一个输出.接下来,我尝试输入a,b,并分配输出,但是出现以下错误:错误C3861:'emxCreate_real_T':找不到标识符

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

函数原型如下所示,本质上是C = A + B:

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];
  }
}

这是我的主要功能:

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?

推荐答案

您缺少包含文件.基于您在评论中提供的链接,可能需要包含一个myTestFunction_emxAPI.h文件.

You're missing an include file. Based on the link you provided in your comment, there is probably a myTestFunction_emxAPI.h file that needs to be included.

此外,我看到您创建的b[2][2]数组正在被for (int i = 0; i < 3; i++)' and for(int j = 0; j< 3; j ++)`循环超出其范围访问.

Also, I see that the b[2][2] array that you created is being accessed beyond its bounds by the for (int i = 0; i < 3; i++)' andfor (int j = 0; j < 3; j++)` loops.

这篇关于在C ++中处理emxArray_real_T数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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