How to pre-allocate table rows
Afficher commentaires plus anciens
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}
Réponse acceptée
Plus de réponses (1)
Subhadra Mahanti
le 8 Fév 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'};
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!