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.

 採用された回答

Adam Danz
Adam Danz 2021 年 11 月 15 日

1 投票

To create an emtpy table with 4 headers,
T = array2table(nan(0,4), 'VariableNames', {'Observations', 'Mean', 'Treatment', 'Residual'})
T = 0×4 empty table
To create 2x4 table of numeric values,
T = array2table(nan(2,4), 'VariableNames', {'Observations', 'Mean', 'Treatment', 'Residual'})
T = 2×4 table
Observations Mean Treatment Residual ____________ ____ _________ ________ NaN NaN NaN NaN NaN NaN NaN NaN

2 件のコメント

Sebastian Daneli
Sebastian Daneli 2021 年 11 月 15 日
@Adam Danz, turns out I missunderstood the purpose of tables. If i wan't to do the same thing but for cells?
Adam Danz
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
Seth Furman 2021 年 11 月 16 日

4 投票

table has a preallocation syntax:
table('Size', [2 4], 'VariableNames', ["Observations", "Mean", "Treatment", "Residual"], 'VariableTypes', repmat("double", 1, 4))
ans = 2×4 table
Observations Mean Treatment Residual ____________ ____ _________ ________ 0 0 0 0 0 0 0 0

2 件のコメント

Adam Danz
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.
Star Strider
Star Strider 2021 年 11 月 16 日
Duly noted! I completely forgot about 'Size'.
Thank you!

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

カテゴリ

ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by