Write string and table (in that order) to text file
Show older comments
I need to write a string and a table to one text file. The string contains a description of the data in the table, but is not the headers for the table. I am using R2019a which I guess means the "Append" writetable option does not work? Please see my example data below:
% Load data
load cereal.mat;
table = table(Calories, Carbo, Cups, Fat, Fiber, Mfg, Name, Potass);
string = {'This is a string about the cereal table'};
filename = "dummyoutput.sfc";
% How I tried to do this (which does not work!)
fid = fopen(filename, 'w', 'n');
fprintf(fid, '%s', cell2mat(string))
fclose(fid);
writetable(table, filename, 'FileType', 'text', 'WriteVariableNames', 0, 'Delimiter', 'tab', 'WriteMode', 'Append')
I get this error (because 'WriteMode' was introduced in R2020a)
Error using writetable (line 155)
Wrong number of arguments.
Does anyone have a workaround for this?
Thanks!
Accepted Answer
More Answers (1)
How about using this function?
4 Comments
Melissa Buechlein
on 13 Jul 2020
Takumi
on 13 Jul 2020
Oops, I'm sorry, I missed it.
How about writing in fprintf instead of writetable?
Melissa Buechlein
on 13 Jul 2020
Categories
Find more on Spreadsheets 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!