フィルターのクリア

Where do MATLAB-created .txt files get saved?

18 ビュー (過去 30 日間)
Alexander Ketzle
Alexander Ketzle 2021 年 11 月 10 日
コメント済み: Alexander Ketzle 2021 年 11 月 10 日
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.
  1 件のコメント
Alexander Ketzle
Alexander Ketzle 2021 年 11 月 10 日
Super helpful and informative, thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by