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?
Pass matlab array to c function as mxArray
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
Réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Coder dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!