print table using printf

34 次查看(过去 30 天)
Metin Akyol
Metin Akyol 2022-2-17
回答: Chunru 2022-2-18
Is there an elegant way to print the content from a table using fprintf?
Right now, I am printing the columns one at a time, underneath each other (into a csv file). I would like print it to a csv file however in the original order with the columns next to each other.
  1 个评论
Voss
Voss 2022-2-17
writetable() may work for what you are trying to do, but if you must use fprintf(), then it may be convenient to convert the table to another data type first using, e.g., table2array() or table2cell().

请先登录,再进行评论。

采纳的回答

Chunru
Chunru 2022-2-18
a = array2table(rand(4,3)); % a simple table
s = formattedDisplayText(a); % formatted display
fid = fopen('test.csv', 'w');
fprintf(fid, s);
fclose(fid);
type test.csv

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by