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 Center および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by