Compile version of program doesn't recognise a file location

1 view (last 30 days)
I created a function to write text to a file in the folder where the matlab file is running. It works fine. but when I compile it, its askign for the file to be in my users\apdata etc folder. How do I get around this as I want to share it and don't want the users to have to do this?
function pathtext = WriteFileToActingDir(hObject, eventdata, handles,text, file ) %Write String 'text' to a file 'file' in the current operating directory % Detailed explanation goes here
prog = mfilename('fullpath'); %Get current program path & name
[progpath,name,ext] = fileparts(prog); %Split out folderpath
pathtext = fullfile(progpath,file); %Build new filename
fid = fopen(pathtext, 'w');
fprintf(fid, '%s', text);
fclose(fid);
end
  1 Comment
Adam
Adam on 30 Oct 2014
I ended up setting up a MATLAB_HOME environment variable that is setup by our compiled programs where needed. This can then be used as a known working directory on the target machine rather than some hard-coded assumption or something that ends up being relative to some strange install folder.
It took a bit of time to get right (we have a config text file too which sits in that location and sets up user preferences) but it did at least solve the problem of where to write files on an arbitrary user's machine.

Sign in to comment.

Accepted Answer

Sean de Wolski
Sean de Wolski on 30 Oct 2014
Use ctfroot for this.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!