writetable with spaces on header

17 次查看(过去 30 天)
I have a table: T
LastName Age Smoker Height Weight BloodPressure
_________ ___ ______ ______ ______ _____________
'Sanchez' 38 true 71 176 124 93
'Johnson' 43 false 69 163 109 77
'Diaz' 40 false 67 133 117 75
What I would like to do is output this table to a text file but with spaces in between LastName and BloodPressure like:
Last Name Age Smoker Height Weight Blood Pressure
_________ ___ ______ ______ ______ _____________
'Sanchez' 38 true 71 176 124 93
'Johnson' 43 false 69 163 109 77
'Diaz' 40 false 67 133 117 75

采纳的回答

Walter Roberson
Walter Roberson 2019-6-14
header = {'Last Name', 'Age', 'Smoker', 'Height', 'Weight', 'Blood Pressure'};
Tcell = [header; table2cell(T)];
writecell(Tcell, 'YourFileName.txt', 'Delimiter', '\t')
  6 个评论
dpb
dpb 2019-6-14
Crystall ball out for repair again, Walter? :)
Eth
Eth 2019-6-14
Installed R2019a and it worked. Thanks a lot.

请先登录,再进行评论。

更多回答(1 个)

dpb
dpb 2019-6-13
You will have to write the table content via fprintf then; the writetable function doesn't have the flexibility to specify alternate headings and column names must be valid Matlab variable names which don't include spaces.

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by