emxarray_creal_t是什么类型?我在用matlab mxarrayCoder把matlab程序'转

matlab - dealing with emxArray_real_T data in C++ - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
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)
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_ 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, *
// define input matrix
double p = 0;
for (int i = 0; i & 3; i++) {
for (int j = 0; j & 3; j++){
p = p + 1;
double k = 0;
for (int i = 0; i & 2; i++) {
for (int j = 0; j & 2; j++) {
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] &&
How should I declare the inputs and output?
You're missing an include file.
Based on the
in your comment, there is probably a myTestFunction_emxAPI.h file that needs to be included.
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.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledHow to use C library created by MATLAB Coder codegen in C program with emxArray arguments? - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
The C function (C static library) created by codegen takes an input argument of type const emxArray_uint32_T and return values of type emxArray_struct_T. As the type suggests, input is an array of uint32 and output is an array of struct.
I'm not sure how to use this function in my C program. For the input, should I declare an array of type uint32_T or use the type emxArray_uint32_T ? For the output, because I don't know the size of the output array, how to declare the array of struct to receive the return values from the function?
I put the question in MATLAB answers but have not luck..
If you look in the directory where you generated code you should find a file named &functionName&_emxAPI.h.
This file declares some utility functions which make constructing and destroying emxArray values simpler.
Using them to create emxArray values ensures that all of the fields are properly initialized and insulates your code from any possible changes to the emxArray type.
In an example I made which takes an array of uint32 values and also returns such an array, I see the following functions:
extern emxArray_uint32_T *emxCreateWrapperND_uint32_T(unsigned int *data, int
numDimensions, int *size);
extern emxArray_uint32_T *emxCreateWrapper_uint32_T(unsigned int *data, int rows,
int cols);
extern emxArray_uint32_T *emxCreateND_uint32_T(int numDimensions, int *size);
extern emxArray_uint32_T *emxCreate_uint32_T(int rows, int cols);
extern void emxDestroyArray_uint32_T(emxArray_uint32_T *emxArray);
The first four functions can be used to create emxArray values in different situations.
The first pair, i.e. emxCreateWrapper_uint32_T, emxCreateWrapperND_uint32_T, can be used to create a uint32 emxArray with the specified number of dimensions and sizes from existing data.
So if you already have the input data allocated in some memory, these functions wrap that data up into an emxArray of the specified size without allocating extra memory for your data.
/* Create a 10-by-10 C array of uint32 values and wrap an emxArray around it */
uint32_T x[100];
emxArray *pEmx = NULL;
int k = 0;
for (k = 0; k & 100; k++) {
x[k] = (uint32_T)
pEmx = emxCreateWrapper_uint32_T(x, 10, 10);
/* Use pEmx here*/
/* Deallocate any memory allocated in pEmx. */
/* This DOES NOT free pEmx-&data because the "wrapper" function was used */
emxDestroyArray_uint32_T(pEmx);
The second pair, i.e. emxCreate_uint32_T, emxCreateND_uint32_T, also create emxArray values.
However, they also heap allocate storage for the data field of the emxArray.
This memory will be large enough to hold the number of elements specified in their respective size arguments
After calling these, you will need to populate the data stored in the data field of the returned emxArray struct:
/* Allocate a 10-by-10 uint32 emxArray and fill the values */
int k = 0;
emxArray *pEmx = emxCreate_uint32_T(10, 10);
for (k = 0; k & 100; ++k) {
pEmx-&data[k] = (uint32_T)
/* Use pEmx here*/
/* Deallocate any memory allocated in pEmx. */
/* This DOES free pEmx-&data */
emxDestroyArray_uint32_T(pEmx);
The last, emxDestroyArray_uint32_T, will be used to destroy the array and deallocate any memory allocated by the previous methods.
Finally, to capture your output, you could use emxCreate_struct_T or emxCreateND_struct_T to create an empty emxArray of struct_T values with the proper number of dimensions by passing 0 for one or more sizes where appropriate.
The generated code will allocate enough memory to hold the resulting data in your output emxArray at runtime.
You can then check the size field of this output emxArray to view the sizes of the dimensions of the data field and extract the data as you wish.
The documentation for using emxArray arguments is available .
You need to use emxArray_uint32_T and emxArray_struct_T.
All of the MATLAB Coder defined datatypes that the code uses (and you need to use) are defined in the YourLibName_types.h header file.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
The week's top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
Stack Overflow works best with JavaScript enabled[Mathworks官方视频]使用MATLAB Coder从MATLAB生成C&C++代码
分享这个视频的人喜欢
热门视频推荐
热门日志推荐
同类视频推荐
北京千橡网景科技发展有限公司:
文网文[号··京公网安备号·甲测资字
文化部监督电子邮箱:wlwh@··
文明办网文明上网举报电话: 举报邮箱:&&&&&&&&&&&&
请输入手机号,完成注册
请输入验证码
密码必须由6-20个字符组成
下载人人客户端
品评校花校草,体验校园广场我用matlab2011a的matlab coder将.m文件转换成.C文件的时候总是失败_百度知道
我用matlab2011a的matlab coder将.m文件转换成.C文件的时候总是失败
bat.Run mex -setup to select the MEX compiler and create the MEX options filefail提示:Could not locate the MEX compiler options file mexopts.请教高手怎么回事
提问者采纳
你先安装设计编译器 mbuild - setupy1ymcc -mfun.m
这位大哥,编译器如何安装啊?请教了,急用...有没有网址什么的?
你装的matlab本来就有编译器的!你在命令窗口敲上面的命令就装好了
提问者评价
谢谢,搞定了
其他类似问题
为您推荐:
文件转换的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁}

我要回帖

更多关于 matlab coder使用教程 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信