Pass matlab array to c function as mxArray

1 次查看(过去 30 天)
Hi,
I'm trying to pass a matlab array to a C function but the coder translates the array to a double[] type and I would need a mxArray * type.
Here is the Matlab code:
coder.cinclude('container_wrap.h');
coder.ceval('put_mxArray', 'key', [3 4 5 6]);
The container_wrap.h contains the declaration of put_mxArray:
#ifndef __CONTAINER_H__
#define __CONTAINER_H__
#ifdef __cplusplus
extern "C" {
#else
#include <stdint.h>
#endif
typedef struct mxArray mxArray;
void put_mxArray(char * key, mxArray * val);
void put_uint16_t(char * key, uint16_t val);
uint16_t get_uint16_t(char *key);
#ifdef __cplusplus
}
#endif
#endif /* __CONTAINER_H__ */
The generated code by the coder is this (this is just the piece of generated code that calls put_mxArray):
double dv23[4];
dv23[0] = 3.0;
dv23[1] = 4.0;
dv23[2] = 5.0;
dv23[3] = 6.0;
emxInit_uint8_T(&r18, 3);
emxInit_real_T(&r19, 3);
put_mxArray(cv0, dv23);
Is there a way to force the coder to generate code that passes the array as mxArray ? Can I use the mxArray inside my C code or mxArrays are just for Matlab internal use (can be used only by the generated C code or mex files) and I have to use the more basic types in my C code?
Thank you.
  1 个评论
Bogdan Iliuta
Bogdan Iliuta 2019-12-16
As a more generic question. According to this link I should be able to pass mxArrays in both ways between Matlab and C functions. Do you happen to have any example that does this?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by