C

Asked • 06/19/19

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

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?

1 Expert Answer

By:

Inactive Tutor answered • 4d

Tutor
New to Wyzant

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.