Compile version of program doesn't recognise a file location

1 次查看(过去 30 天)
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 个评论
Adam
Adam 2014-10-30
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.

请先登录,再进行评论。

采纳的回答

Sean de Wolski
Sean de Wolski 2014-10-30
Use ctfroot for this.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by