How to give a structure with arrays in simulink to a custom C code function?

5 views (last 30 days)
I'm trying to give a structure to a C function in Simulink. My steps so far:
- Included the .h & .c in configuration parameters custom code. My header has a structure defind:
typedef struct mystruct
{ int m;
int *i;
double *x;}mystruct
- Now in my MATLAB function under Simulink:
function y = fcn(u)%#codegen
m=int32(1);
i=zeros(10,1,'int32');
x=zeros(10,1);
s.m=m;
s.i=i;
s.x=x;
coder.cstructname(s,'mystruct','extern');
D=int32(0);
D=coder.ceval('accesmystruct',coder.ref(s));
y=10;
If I run the code I get a long error from the code generation that indicates that it can't be compiled in c-code. The error is:
c2_Test2.c
c2_Test2.c(57) : error C2143: syntax error : missing ')' before '*'
c2_Test2.c(57) : error C2081: 'cs_size' : name in formal parameter list illegal
c2_Test2.c(57) : error C2143: syntax error : missing '{' before '*'
c2_Test2.c(57) : error C2059: syntax error : ')'
c2_Test2.c(60) : error C2143: syntax error : missing ')' before '*'
....
This only happens if I declare the two variables `i` and `x` as Pointers. If I declare them as scalar in the header and MATLAB function it works. Does any one see what I'm doing wrong?

Answers (1)

Killian Greliche
Killian Greliche on 21 Jan 2015
Hi,
I've got an answere to my question in "Stackoverflow", so if you are interested hir a link:

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!