MATLAB: Saving to TXT from standalone executable

compilingi/o

Hi all, I've successfully compiled a Matlab program to a standalone executable for Mac OS, but there's only one bug remaining. The program needs to be able to read from and write to a text file. After compiling, this function no longer works, nor does the text file show up anywhere in the "distrib" or "src" directories. Does anyone know what I might be doing wrong?

Best Answer

Typically as mentioned above, the text file will be included in the CTF archive, if it was added as an additional file in deploytool. To access these files, I would consider using the ctfroot command. This command will give you the root directory where the CTF archive is expanded (when run as executable).
For example:
fid = fopen(fullfile(ctfroot,'Name of ExE',filename),'r');
If you want to be able to access this txt file outside of the executable, I would typically not include it in the archive (not add it to deploytool) and provide a full path to the txt file. You can even offer the user the choice to select it using uigetfile.
For example:
[path, fname] = uigetfile('Select file','*.txt');
fid = fopen(fullfile(path,fname),'r');