Append a cell array to an existing CSV file
Show older comments
I have a script that strips a block of data from an input file, does some reformatting, and writes that output to a new CSV file.
I have a mountain of input files, so I've also created a log file that keeps track of what files have already been processed, as well as some useful information about them. In order for the log to be useful I need not just the numerical data, but also the input filename. The script I put together writes the numerical data to the log file:
dlmwrite('LogFile.csv',M, 'delimiter',',','-append'); %Append values to file
But I then have to open the log file, type in the input file name, save it and close it before I can run my script again.
The log data is in a 1 by 13 cell array in which the first 12 values are numerical and the final value in the input file name.
I've been generating the cell array that has all the values I need using the code below:
for i = 1:12 %creates data to append to LogFile
LogData(1,i) = {M(1,i)};
end
LogData(1,13) = {filename};
When I try to append the cell array using dlmwrite I get the following error:
The input cell array cannot be converted to a matrix.
I've tried fprintf as shown below but that "Function is not defined for 'cell' inputs."
fid2 = fopen('LogFile.csv', 'a+');
fprintf(fid, '%s %s %s %s %s %s %s %s %s %s %s %s %s\n', LogData);
fclose(fid);
Any thoughts are appreciated.
Thank you,
RS
Answers (0)
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!