How to read in m-files into a Matlab-generated-Exe
Show older comments
Hello,
my program (that I want to be used as exe) shall do three tasks:
1.: Read-in m-files in which specification-data is stored (e.g. offset =5°/s)
2.: Compare the values from several of the m-files that are in the same folder.
3.: Enable the creation of further specification-m-files so that more comparisons can be done.
When I hardcode the names of the specification-m-files, my script (as exe) is able to read in files.
For the case of reading-in all files from the folder with a special prefix (SNS for sensor) I used a for loop and an eval-command.
This does not work.
For that case I included the already existing m-files during the compilation in the field "Files required for your application to run".
The files that I inlcuded there are available in the exe, but none of the new files that I produce in step 3.
I also tried pragmas, but this does not help.
One curious observation:
the compiler automatically includes three of my multiple specification-files, but I did not name them anywhere.
Thanks in advance
Answers (2)
Steven Lord
on 10 Mar 2026
0 votes
From the documentation "MATLAB Runtime only works on MATLAB code that was encrypted when the deployable archive was built. Any function or process that dynamically generates new MATLAB code will not work against MATLAB Runtime."
Walter Roberson
on 10 Mar 2026
0 votes
You will not be able to use a compiled executable to execute arbitrary .m files: compiled executables are specifically designed to prevent the possibility.
You will need to treat the .m files as data files, treating them as text to be parsed.
To help with this, you can potentially use FEX contributions such as https://www.mathworks.com/matlabcentral/fileexchange/55766-ini -- depending how the text is structured.
If you are going to restructure the files, it might make sense to use JSON encoding for the new files.
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!