MATLAB: Copy table to a .txt file

savetable

Hello, I have a problem printing a table in a .txt file. I cannot find a command that do it properly (I tried with 'save', 'csvwrite', 'writeable'). What I have is a Table 10X4.
Furthermore, how can I have a different format (%20.12f, %12.5e etc…) for each column? Thanks

Best Answer

You can try writematrix() if all values are numeric, by converting your table to an array. If you want to specify the format, then use fprintf
T % 10x4 table
T_array = table2array(T);
fid = fopen('filename.txt', 'w');
fprintf(fid, '%20.12f\t %12.5e\t %f\t %f\n', T_array.');
fclose(fid)