Saving current progam folder path
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jason
am 27 Mär. 2014
Kommentiert: Jason
am 27 Mär. 2014
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?
Akzeptierte Antwort
Jacob Halbrooks
am 27 Mär. 2014
Bearbeitet: Jacob Halbrooks
am 27 Mär. 2014
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!