Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an empty table of size with headers in Matlab

Tags:

matlab

I would like to create a table of 5 columns and 10000 rows, such that it has headers with empty cells in the beginning. I will fill in the cells with strings or numbers later after calculation. How to do that? Thanks.

Jen

like image 914
JenZ Avatar asked Jul 15 '15 17:07

JenZ


People also ask

How do you make an empty table in MATLAB?

The only 'empty' table MATLAB can create, is 0x0. To check this, create a table T of non-zero dimestions: just give it a size and some variable names and types. It will be populated with zeroes for the numeric datatypes, and non-empty cells containing an empty double for cells.

How is an empty table created?

If you want the table to be empty use the WHERE 1=0 or TOP (0) on both sides of the UNION ALL. If you want a copy of the table with data then just put the WHERE 1=0 or TOP (0) on one side.

How do you show headers in MATLAB?

Description. s = getHeader( obj ) returns the text used as the header when displaying obj . This method is called once for the entire object array.

How do you get the size of a table in MATLAB?

Description. H = height( T ) returns the number of rows in the table, T . height(T) is equivalent to size(T,1) .


1 Answers

Here is a way:

Let's say you have the following headers:

headers = {'A' 'B' 'C' 'D' 'E'};

Then initialize the data (in your case 10 000 x 5, here 4 x 5) as an empty cell. Then convert to a table and edit the VariableNames property to make it the headers:

data = cell(4,5);
T = cell2table(data);
T.Properties.VariableNames = headers

Output:

T = 

    A     B     C     D     E 
    __    __    __    __    __

    []    []    []    []    []
    []    []    []    []    []
    []    []    []    []    []
    []    []    []    []    []
like image 161
Benoit_11 Avatar answered Sep 30 '22 18:09

Benoit_11