What is the proper syntax for feeding a C struct (defined in a header file) to a MATLAB function?
Mostrar comentarios más antiguos
SUMMARY: With MATLAB Coder, what is the proper syntax for passing a C struct (defined in a header file) to a MATLAB function?
- define a C struct in a header file,
- defined a MATLAB equivalent of the struct with coder.typeof commands, and finally
- link the two types of structs with a coder.cstructname command.
I want to use a C main function to
- create an instance of a C struct (that is defined in a header file, say mystruct.h) and
- feed that struct to a MATLAB function (defined in an m-file, say foo.m, containing a %#codegen notification).
- Suppose p is an instance of the C struct.
- Suppose also that main.c has #include "mystruct.h".
- Suppose that the main C function calls foo with foo(p);.
If the struct class T is defined by defining the individual fields and ending with
T = coder.cstructname(T,'mystruct','extern','HeaderFile','mystruct.h');
will MATLAB Coder infer the correct input type for foo with the following sequence of commands for code generation?
cfg = coder.config('exe')
cfg.CustomSource = 'main.c'
cfg.CustomInclude = 'mystruct.h'
codegen -config cfg foo -args {T}
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Algorithm Design Basics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!