Saving current progam folder path
2 次查看(过去 30 天)
显示 更早的评论
Hi. I want to save the location of the current m file folder.
%Save current app directory to a txt file
prog = mfilename('fullpath'); %Get current program path & name
[progpath,name,ext] = fileparts(prog); %Split out folderpath
pathtext = fullfile(progpath,'lastdir.txt') %Build new filename
save('pathtext','progpath','-ascii');
But using the above results in the text file (lastdir.txt) containing only numbers?
采纳的回答
Jacob Halbrooks
2014-3-27
编辑:Jacob Halbrooks
2014-3-27
It looks like you want to write a string to the text file, but SAVE is not a good fit for this. The help for SAVE -ASCII explains:
* MATLAB translates characters to their corresponding internal
ASCII codes. For example, 'abc' appears in an ASCII file as:
9.7000000e+001 9.8000000e+001 9.9000000e+001
I would suggest you use a different function for writing the file, such as FPRINTF:
prog = mfilename('fullpath'); %Get current program path & name
[progpath,name,ext] = fileparts(prog); %Split out folderpath
pathtext = fullfile(progpath,'lastdir.txt') %Build new filename
fid = fopen(pathtext, 'w');
fprintf(fid, '%s', progpath);
fclose(fid);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!