How to append data from multiple runs of script without overwriting previous data.

4 次查看(过去 30 天)
Hi,
My code follows. Everything is correct except that only the value from the last run of the script is saved in the output file. Please can someone help?
The commands commented out also have been tried and do not work. Please help me...
numfilesx = 2
numfilesy = 2
OutputFilePath = 'C:\1Feb19 output';
OutputFilePhase = 'PhaseDiff.csv';
for x = 0:numfilesx
for y = 0:numfilesy
myfilename = sprintf("C:\\1Feb19_final\\row%d_%d.csv", y, x);
PhaseDiff = atan (Y1(1)/Z1(1));
csvwrite(filenamePhase,PhaseDiff,x,y)
%dlmwrite(filenamePhase,PhaseDiff,'delimiter',' ','roffset',1)
%filenamePhase = fullfile(OutputFilePath, OutputFilePhase);
%[fid1, msg] = fopen(filenamePhase, 'wt');
%if fid1 < 0
% error('Could not open file "%s" because "%s"', fid1, msg);
%end
%fprintf(fid1, '%s\n', PhaseDiff);
fclose('all');
end
end

采纳的回答

Rik
Rik 2019-5-15
Use one of the append options from fopen:
'r' Open file for reading.
'w' Open or create new file for writing. Discard existing contents, if any.
'a' Open or create new file for writing. Append data to the end of the file.
'r+' Open file for reading and writing.
'w+' Open or create new file for reading and writing. Discard existing contents, if any.
'a+' Open or create new file for reading and writing. Append data to the end of the file.
'A' Open file for appending without automatic flushing of the current output buffer.
'W' Open file for writing without automatic flushing of the current output buffer.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by