Where do MATLAB-created .txt files get saved?

18 次查看(过去 30 天)
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!

采纳的回答

Jan
Jan 2021-11-10
编辑:Jan 2021-11-10
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.

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by