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일

0 개 추천

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일
Oh, yeat, forgot they'd introduced that, Walter...I need to find the time to update/reinstall...but not yet today! :(
Eth
Eth 2019년 6월 14일
Hi Walter,
Thanks. I'm getting the following error:
Undefined function or variable 'writecell'.
I'm trying to do this:
writecell(Tcell,[folder filename], 'Delimiter', '\t')
Where folder is just the path to the folder containing the file and filename is the name of the file
'C:\myfiles\001\YourFileName.txt'
dpb
dpb 2019년 6월 14일
writecell was not introduced until R2019a so you'll have to have lastest version to use it.
Walter Roberson
Walter Roberson 2019년 6월 14일
It is difficult to make appropriate recommendations when we do not know the release being used.
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일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

태그

질문:

Eth
2019년 6월 13일

댓글:

Eth
2019년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by