フィルターのクリア

Help with saving data in .txt file

2 ビュー (過去 30 日間)
aurc89
aurc89 2015 年 1 月 11 日
コメント済み: aurc89 2015 年 1 月 12 日
Hi guys, I have a simple question about how to save data. Let's suppose I have two vectors, x and y; I want to save them as a .txt file having two columns given by x and y. I want also to decide the name of the file (e.g. 'myfile.txt') and the directory of the folder where I save the file (e.g. 'C:\\User\Desktop\MyFolder\') in the code. Thank you!

採用された回答

Image Analyst
Image Analyst 2015 年 1 月 11 日
編集済み: Image Analyst 2015 年 1 月 12 日
Try this:
% Get the name of the file that the user wants to save.
startingFolder = userpath
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
fid = fopen(fullFullFileName, 'wt');
if fid ~= -1
for row = 1 : length(x)
fprintf(fid, '%f, %f\n', x(k), y(k));
end
fclose(fid);
end
  3 件のコメント
Image Analyst
Image Analyst 2015 年 1 月 12 日
Try putting the file handle into fprintf:
fprintf(fid, '%f, %f\n', x(row), y(row)); % To file.
fprintf(1, '%f, %f\n', x(row), y(row)); % To command window.
aurc89
aurc89 2015 年 1 月 12 日
Thank you !

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by