How to write data into .txt file

2 ビュー (過去 30 日間)
Utsav Dobhi
Utsav Dobhi 2020 年 7 月 6 日
コメント済み: Image Analyst 2020 年 7 月 16 日
How should i write the AVG and standard deviation data into .txt file?
d = 'E:\\ \\ DummyFile\\';
filePattern = fullfile(d, 'Run*');
file = dir(filePattern)
n = length(file)
for k = 1:n
baseFileName = file(k).name;
FullFileName = fullfile(d, baseFileName, 'dummy.csv');
temp = readtable(FullFileName, 'ReadVariableNames' true, 'ReadRowsNames' true);
x(:, :, k) = temp(:, :);
end
%Finding Average and Std
Avg = mean(x,3);
Standard_deviation = std(x,0,3)

採用された回答

Image Analyst
Image Analyst 2020 年 7 月 6 日
% Ask for the name of the file that the user wants to save.
startingFolder = pwd % or wherever you want.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
% Open file for writing.
fid = fopen(fullFileName, 'wt');
if fid ~= -1
% Was able to open it successfully, now write stuff into it.
fprintf(fid, 'Average = %f.\nStandard Deviation = %f.\n', Avg, Standard_deviation);
fclose(fid);
else
errorMessage = sprintf('Error opening %s for output.', fullFileName);
uiwait(errordlg(errorMessage));
end
  3 件のコメント
Utsav Dobhi
Utsav Dobhi 2020 年 7 月 15 日
How should i generate three different files with given one file name. SO i want to create three different output.csv for AVGT, stdT, and SlopeT data.
Image Analyst
Image Analyst 2020 年 7 月 16 日
Simply change the filename before each call to writetable().
fullFileName = 'AvgT.csv';
writetable(AvgT, fullFileName, 'Delimiter', ',', 'WriteRowNames', true);
fullFileName = 'StdT.csv';
writetable(StdT, fullFileName, 'Delimiter', ',', 'WriteRowNames', true);
fullFileName = 'SlopeT.csv';
writetable(SlopeT, fullFileName, 'Delimiter', ',', 'WriteRowNames', true);

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2020 年 7 月 6 日
編集済み: madhan ravi 2020 年 7 月 6 日
doc writematrix % after converting your data into a table
%or
doc dlmwrite

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by