MATLAB Answers

Eth
0

writetable with spaces on header

Asked by Eth
on 13 Jun 2019
Latest activity Commented on by Eth
on 14 Jun 2019
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

  0 Comments

Sign in to comment.

2 Answers

Answer by Walter Roberson
on 14 Jun 2019
 Accepted Answer

header = {'Last Name', 'Age', 'Smoker', 'Height', 'Weight', 'Blood Pressure'};
Tcell = [header; table2cell(T)];
writecell(Tcell, 'YourFileName.txt', 'Delimiter', '\t')

  6 Comments

It is difficult to make appropriate recommendations when we do not know the release being used.
dpb
on 14 Jun 2019
Crystall ball out for repair again, Walter? :)
Eth
on 14 Jun 2019
Installed R2019a and it worked. Thanks a lot.

Sign in to comment.


dpb
Answer by dpb
on 13 Jun 2019

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.

  0 Comments

Sign in to comment.