Creating a table with only headers
조회 수: 91 (최근 30일)
이전 댓글 표시
I would like to create an empty table with the headers 'Observations', 'Mean', 'Treatment' and 'Residual'. I would also like the predetermine the amount of data to fit in the table, i.e., if I have two 2 sets, the table should allow for 2*4 inputs.
댓글 수: 0
채택된 답변
Adam Danz
2021년 11월 15일
To create an emtpy table with 4 headers,
T = array2table(nan(0,4), 'VariableNames', {'Observations', 'Mean', 'Treatment', 'Residual'})
To create 2x4 table of numeric values,
T = array2table(nan(2,4), 'VariableNames', {'Observations', 'Mean', 'Treatment', 'Residual'})
댓글 수: 2
Adam Danz
2021년 11월 15일
You can't add header names for cells but to preallocate the cells in the same way I've shown for tables,
C = cell(0,4)
or
c = cell(2,4)
추가 답변 (1개)
Seth Furman
2021년 11월 16일
table has a preallocation syntax:
table('Size', [2 4], 'VariableNames', ["Observations", "Mean", "Treatment", "Residual"], 'VariableTypes', repmat("double", 1, 4))
댓글 수: 2
Adam Danz
2021년 11월 16일
Thanks Seth.
@Sebastian Daneli, this solution also allows you to set the variable types which is quite useful. This is the better answer.
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!