Print table to text file

32 views (last 30 days)
Kellerautomat
Kellerautomat on 16 Jan 2018
Answered: Sruthi Geetha on 25 Jan 2018
Hi everyone, I'm trying to print a table which I created to an existing text file
I'm aware that a table is not a char and therefore the fprint does not work, but I really don't know how I could save the table to my file... I'd be glad if someone could help me! Thanks in advance!
if true
tableT=table(Number,Response,Time,Date);
structtableT(1,1).Number=num;
structtableT(1,1).Response='correct';
structtableT(1,1).Time=time;
structtableT(1,1).Date=date;
tableT=[tableT;struct2table(structtableT)];
fid = fopen(file, 'a+');
fprintf(fid, '\n%s', tableT);
fclose(fid);
end

Answers (1)

Sruthi Geetha
Sruthi Geetha on 25 Jan 2018
You can use the 'writetable' function to write a table to a text file. The syntax is: writetable(T,filename) where T is the table and filename is the name of file with extension. The extension must be one of the following: .txt, .dat, or .csv for delimited text files .xls, .xlsm, or .xlsx for Excel spreadsheet files .xlsb for Excel spreadsheet files supported on systems with Excel for Windows

Community Treasure Hunt

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

Start Hunting!