フィルターのクリア

Adding column headers to writetable csv file

206 ビュー (過去 30 日間)
Erika Joh
Erika Joh 2019 年 4 月 29 日
コメント済み: Adam Danz 2021 年 9 月 13 日
I'm trying to figure out how to add column headers to my csv files using writetable.
I started with creating a table of variables (transposed into columns) and then used writetable to export it as a csv. Right now the headersin the output file are Var1 and Var2. How can I change this?
T6 = table(average_in_bin.',num_per_bin.');
writetable(T6,'avg_num_per_bin.csv')

採用された回答

Adam Danz
Adam Danz 2019 年 4 月 29 日
編集済み: Adam Danz 2021 年 9 月 13 日
The default value for the WriteVariableNames parameter in writetable() is true so all you need is to add variable names to your 'T6' table. Below I named them "NameOne" and "NameTwo".
T6 = table(average_in_bin.',num_per_bin.', 'VariableNames', {'NameOne', 'NameTwo'});
writetable(T6, 'avg_num_per_bin.csv', 'WriteVariableNames', true)
  3 件のコメント
CMatlabWold
CMatlabWold 2021 年 9 月 11 日
I believe the "True" has to be lowercase.
writetable(T6, 'avg_num_per_bin.csv', 'WriteVariableNames', true)
Adam Danz
Adam Danz 2021 年 9 月 13 日
Yep, thanks. Corrected.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by