How to pre-allocate table rows
Show older comments
What is the clean way to preallocate rows in a table?
Here is an example to illustrate what I would like:
a = {'a'}
b = 1
a = table( a, b )
a(10,:) = %Some placeholder value to ensure table is extended to be 10 rows
In the example above, the table is trivial, so I could write out the following line. But since the types are known, then MATLAB could in theory just fill this in by itself.
a(10,:) = {{[]}, 0}
Accepted Answer
More Answers (1)
Subhadra Mahanti
on 8 Feb 2016
I can think of several ways to do it depending on your data. One way would be: create a cell array of row x column and covert that to a table
data=cell(5,3);
myTable = cell2table(data);
% You can alwayschange the variable names of the table later
myTable.Properties.VariableNames = {'Col1', 'Col2', 'Col3'};
myTable.Properties.RowNames = {'Row1', 'Row2', 'Row3','Row4','Row5'};
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!