How to use #inlcude <>? # is declared as an invalid character!
2 views (last 30 days)
Show older comments
Justus Fassnacht
on 9 Apr 2021
Commented: Justus Fassnacht
on 14 Apr 2021
#include <stdio.h> /* matlab tells me # is an invalid character, but i thougt it belongs there*/
#include <stdlib.h> /* any suggestion? I am a mere beginner so it probably has a simple reason*/
int main()
{
}
0 Comments
Accepted Answer
Walter Roberson
on 9 Apr 2021
MATLAB will not tell you that if your file extension is .c
2 Comments
Walter Roberson
on 13 Apr 2021
I see you Unaccepted my Answer, so you must be looking for a different solution.
#include <stdio.h> /* matlab tells me # is an invalid character, but i know for fact that it belongs there*/
MATLAB permits the # character in the following contexts:
- In comments
- Inside '' character vectors
- Inside "" string scalars
The code you posted is C code (not even C++). MATLAB does not permit C code in .m (MATLAB) or .mlx (Live Script) files, except in the forms noted above. Instead if you need to #include a C header file inside MATLAB code, you need to use coder.cinclude() and you would call upon the functions using coder.ceval(); see https://www.mathworks.com/help/simulink/ug/incorporate-c-code-using-a-matlab-function-block.html
Simulink uses the same tools of coder.cinclude() and coder.ceval() inside MATLAB Function Blocks, and does not permit C code directly.
MATLAB permits linking to compiled C or C++ code, which would be stored in .c or .cpp or .C or .CPP files or .c++ or .C++ files, but not in .m files.
What is your evidence that "for certain" a #include statement belongs in a .m file ?
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!