Where do MATLAB-created .txt files get saved?
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alexander Ketzle
el 10 de Nov. de 2021
Comentada: Alexander Ketzle
el 10 de Nov. de 2021
I'm a student looking to do some basic data analysis from files using MATLAB, and was learning how to use fopen and related commands, currently I'm making a dummy file and reading it using this code:
fileName = 'nums.txt';
x = 1:1:5;
y = [x;rand(1,5)];
fileID = fopen(fileName,'w');
fprintf(fileID,'%g %g\n',y);
fclose(fileID);
disp('file start');
type nums.txt
disp('file end');
fileID = fopen(fileName,'r');
formatSpec = '%g %g';
sizeA = size(y);
A = fscanf(fileID,formatSpec,sizeA)';
I just have one question: Where does MATLAB store this file? Is there a specified directory? And could I specify the full path of where the file gets saved?
Thank you!
0 comentarios
Respuesta aceptada
Jan
el 10 de Nov. de 2021
Editada: Jan
el 10 de Nov. de 2021
If you do not specify a folder, the current directory is used. See
help cd
help pwd
Note, that pwd is just a wrapper function for cd , so prefer the later command.
Of course you can specify a folder:
fileName = fullfile(cd, 'nums.txt');
fileName = fullfile(tempdir, 'nums.txt');
fileName = 'D:\my\sub\folder\nums.txt'
... etc
After starting Matlab the current folder can be defined differently according to the chosen preferences. It can be a fixed folder, the last active folder in the former Matlab session or the user folder, e.g. under Windows "%APPDATA%\MATLAB" or similar.
Más respuestas (0)
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!