MATLAB: How to use an external settings file to allow a user of the compiled standalone application to configure the application

configurationctfrootdeploymentMATLABsettings

I would like to have a settings file that I deploy with my application so that the user can configure certain settings about my application before they execute it.
I tried to create the settings file in same directory as my applications executable and then read the settings file with the "fopen" function in my application, but the settings file cannot be found.
What is the best approach to use an external settings file to allow a user of my compiled standalone application to configure the application before execution?

Best Answer

There are two common ways to use a settings file with a compiled application:
1) Use a hard-coded full path to locate the settings file (such as "C:\mySettings.xlsx") and inform the user to place their personal settings file at that location.
2) Ask the user where the settings file they would like to use is located. In a command line application, this can be achieved by passing the settings file path as an argument when you start the application.
The reason why we avoid relative paths to external files in compiled applications is because the application will look for files relative to the "ctfroot" directory, not the directory where the application's .exe is located. Relative paths are fine for files you compile into your application, because they will be extracted to the "ctfroot" directory, but they do not work well for files you want to store alongside your application.