How do I include a header file in MATLAB code?

29 visualizaciones (últimos 30 días)
Megan O'Brien
Megan O'Brien el 17 de Jul. de 2017
Editada: dpb el 9 de Dic. de 2021
I'm quite new to MATLAB and I'm trying to make a header file and include it in my MATLAB code. The header file contains a lot of constants and calculations that would be needed in the main code. I'm not sure first of all though how to save the header file, (should it be .m?) and also what's the line of code needed to include it in a MATLAB code. I'm only getting answers for including C/C++ header files in MATLAB. Apologies if this is a really basic question!

Respuesta aceptada

dpb
dpb el 17 de Jul. de 2017
Editada: dpb el 9 de Dic. de 2021
It's a really basic question but Matlab m-file syntax doesn't include the facility.
One way you can simulate it is to make the information in the header into a function that is then called by the higher level function.

Más respuestas (1)

thayalan thayalan
thayalan thayalan el 9 de Dic. de 2021
During mex build the following error observed , how to solve this error ?
  3 comentarios
thayalan thayalan
thayalan thayalan el 9 de Dic. de 2021
#define that defines the uint8_T should be there with Matlab compiler and also "C" extension should not create an issue.. I am misssing somthing about compiler but i can't able to find it out.
dpb
dpb el 9 de Dic. de 2021
Editada: dpb el 9 de Dic. de 2021
Still looks to me like the preprocessor isn't being called...I don't write much C at all and am just beginning to play with gcc the last few days, so I'm still pretty raw. I am almost exclusively Fortran and there the preprocessor isn't automagically invoked if the source input file name doesn't begin with an uppercase "F" -- but the C compiler should call it anyway -- altho I do see the doc says does need the extension.
I'd try the "-E" option to force the preprocessor to run and echo the preprocssed file output to see what it actually sees and if that resolves the missing macro.
Would have to see the full source file to be able to diagnose anything further...

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by