save .TXT inside a specific folder

9 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2022 年 11 月 22 日
コメント済み: Mathieu NOE 2022 年 11 月 23 日
Hi. I am trying to save a .TXT file inside a certain folder. I am currently using this code, but something is not working....
new_folder = 'C:\Users\....\Folder A'
A = ; % matrix 200x3 double
save('file.txt', 'A') % saves in the current folder
out = fullfile(new_folder, A); % ??

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 11 月 22 日
hello
try this
new_folder = 'C:\Users\....\Folder A'
A = ; % matrix 200x3 double
save(fullfile(new_folder, 'file.txt'), 'A') % saves in the current folder
  2 件のコメント
Alberto Acri
Alberto Acri 2022 年 11 月 22 日
編集済み: Alberto Acri 2022 年 11 月 22 日
Okay, thank you @Mathieu NOE!
While if 'A' is just a number? I tried the code above but it doesn't work.
new_folder = 'C:\Users\....\Folder A'
A = 300;
save(fullfile(new_folder, 'file.txt'), 'A') % saves in the current folder
Mathieu NOE
Mathieu NOE 2022 年 11 月 23 日
hello
if you use save and you want a readable txt file, you have to specify that you want ascii format.
Otherwise save will stick to the default format which is binary
% FORMAT: Specify the format of the file, regardless of any specified
% extension. Use one of the following combinations:
%
% '-mat' Binary MAT-file format (default).
% '-ascii' 8-digit ASCII format.
% '-ascii', '-tabs' Tab-delimited 8-digit ASCII format.
% '-ascii', '-double' 16-digit ASCII format.
% '-ascii', '-double', '-tabs' Tab-delimited 16-digit ASCII format.
A = 300;
% A = randn(10,3);
save(fullfile(new_folder, 'file.txt'), 'A', '-ascii') % saves in the new folder
FYI, now matlab also has writematrix for the same job (with more options)
writematrix(A, fullfile(new_folder, 'file.txt')) % saves in the new folder

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by