Pass matlab array to c function as mxArray

조회 수: 1 (최근 30일)
Bogdan Iliuta
Bogdan Iliuta 2019년 12월 12일
댓글: Bogdan Iliuta 2019년 12월 16일
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