How do I include a header file in MATLAB code?

29 次查看(过去 30 天)
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!

采纳的回答

dpb
dpb 2017-7-17
编辑:dpb 2021-12-9
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.

更多回答(1 个)

thayalan thayalan
thayalan thayalan 2021-12-9
During mex build the following error observed , how to solve this error ?
  3 个评论
thayalan thayalan
thayalan thayalan 2021-12-9
#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 2021-12-9
编辑:dpb 2021-12-9
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...

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by