Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

table

Table array with named variables that can contain different types

Description

table arrays store column-oriented or tabular data, such as columns from a text file or spreadsheet. Tables store each piece of column-oriented data in a variable. Table variables can have different data types and sizes as long as all variables have the same number of rows. Use the summary function to get information about a table.

To index into a table, use smooth parentheses () to return a subtable or curly braces {} to extract the contents. You can reference variables and rows using names. For more information on indexing using numbers and names, see Access Data in a Table.

Creation

You can read data from a file into a table using either the Import Tool or the readtable function. Alternatively, use the table function described below to create a table from existing workspace variables.

You also can create a table that allows space for variables whose values are filled in later. To create a table with preallocated space for variables, use the table function with 'Size' as the first input argument, as described below.

Syntax

T = table(var1,...,varN)
T = table('Size',sz,'VariableTypes',varTypes)
T = table(___,'VariableNames',varNames)
T = table(___,'RowNames',rowNames)
T = table

Description

example

T = table(var1,...,varN) creates a table from the input variables var1,...,varN. Variables can be of different sizes and data types, but all variables must have the same number of rows.

example

T = table('Size',sz,'VariableTypes',varTypes) creates a table and preallocates space for the variables that have data types you specify. sz is a two-element numeric array, where sz[1] specifies the number of rows and sz[2] specifies the number of variables. varTypes is a cell array of character vectors specifying data types.

example

T = table(___,'VariableNames',varNames) specifies the names of the variables in the output table. You can use this syntax with the input arguments from any of the other syntaxes for this function.

example

T = table(___,'RowNames',rowNames) specifies names of the rows in the output table. You can use this syntax with the input arguments of any of the previous syntaxes.

example

T = table creates an empty 0-by-0 table.

Input Arguments

expand all

Input variables, specified as arrays with the same number of rows. The input variables can be of different sizes and different data types.

Common input variables are numeric arrays, logical arrays, character arrays, structure arrays, or cell arrays. Input variables also can be objects that are arrays. Such an array must support indexing of the form var(index1,...,indexN), where index1 is a numeric or logical vector that corresponds to rows of the variable var. In addition, the array must implement both a vertcat method and a size method with a dim argument.

Example: table([1:4]',ones(4,3,2),eye(4,2)) creates a table from variables with four rows, but different sizes.

Example: table([1:3]',{'one';'two';'three'},categorical({'A';'B';'C'})) creates a table from variables with three rows, but different data types.

Size of the preallocated table, specified as a two-element numeric vector. The first element of sz specifies the number of rows, and the second element specifies the number of table variables.

To create variables only, without any rows, specify 0 as the first element of sz.

Example: T = table('Size',[50 3],'VariableTypes',{'string','double','datetime'}) preallocates 50 rows for a table that contains a string array, a double array, and a datetime array.

Example: T = table('Size',[0 4],'VariableTypes',varTypes) specifies zero rows and four variables.

Data types of the variables in a preallocated table, specified as a cell array of character vectors. The number of types specified by varTypes must equal the number of variables specified by the second element of sz.

If you specify 'char' as a data type, then table preallocates the corresponding variable as a cell array of character vectors, not as a character array. Best practice is to avoid creating table variables that are character arrays. When working with text data in a table or a timetable, consider using a string array or a categorical array.

varTypes can contain the names of any data types, including the names shown in the table.

'single'Single-precision number
'double'Double-precision number
'int8'Signed 8-bit integer
'int16'Signed 16-bit integer
'int32'Signed 32-bit integer
'int64'Signed 64-bit integer
'uint8'Unsigned 8-bit integer
'uint16'Unsigned 16-bit integer
'uint32'Unsigned 32-bit integer
'uint64'Unsigned 64-bit integer
'logical'Logical 1 (true) or 0 (false)
'char'Character
'string'String array
'struct'Structure array
'cell'Cell array
'table'Table
'function_handle'Function handle

Names of the variables in the output table, specified as a cell array of character vectors. The number of names in varNames must equal the number of variables.

Names of the rows in the output table, specified as a cell array of character vectors. The number of names in rowNames must equal the number of rows.

Example: T = table([10;20;30],{'M';'F';'F'},'VariableNames',{'Age','Gender'},'RowNames',{'P1','P2','P3'}) creates a table with both variable names and row names.

Properties

expand all

Access Table Metadata Properties

A table contains metadata properties that describe the table and its variables. Access these properties using the syntax tableName.Properties.PropertyName, where PropertyName is the name of a property. For example, you can access the names of the variables in table T using the syntax T.Properties.VariableNames.

You can return a summary of all the metadata properties using the syntax tableName.Properties.

Tables provide metadata access through the Properties property because you can access table data directly using dot syntax. For example, if table T has a variable named Var1, then you can access the variable as an array using the syntax T.Var1.

Table Metadata

Dimension names, specified as a two-element cell array of character vectors.

You can access table data using the two dimension names. If the table has row names, and you use dot syntax and the first dimension name, then you can access the row names as a vector. If you use dot syntax and the second dimension name, then the data from all the variables are concatenated together in one array, as though you had indexed into the timetable using {:,:} syntax.

Example

Create a table and display its dimension names. You can access row names and data using dimension names with dot syntax.

load patients
T = table(Age,Height,Weight,Systolic,Diastolic, ...
          'RowNames',LastName);
T.Properties.DimensionNames
ans = 1×2 cell array
    {'Row'}    {'Variables'}

Access the row names using the first dimension name. Display the first five names.

T.Row(1:5)
ans = 5×1 cell array
    {'Smith'   }
    {'Johnson' }
    {'Williams'}
    {'Jones'   }
    {'Brown'   }

Access the data using the second dimension name. This syntax is equivalent to T{:,:}.

T.Variables
ans = 100×5

    38    71   176   124    93
    43    69   163   109    77
    38    64   131   125    83
    40    67   133   117    75
    49    64   119   122    80
    46    68   142   121    70
    33    64   142   130    88
    40    68   180   115    82
    28    68   183   115    78
    31    66   132   118    86
      ⋮

Modify the names of its dimensions using the Properties.DimensionNames property. Having changed the dimension names, you can access the row times and data using the syntaxes T.Patient and T.Data respectively.

T.Properties.DimensionNames = {'Patient','Data'};
T.Properties
ans = struct with fields:
             Description: ''
                UserData: []
          DimensionNames: {'Patient'  'Data'}
           VariableNames: {'Age'  'Height'  'Weight'  'Systolic'  'Diastolic'}
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowNames: {100×1 cell}

Row names, specified as a cell array of character vectors that are nonempty and distinct. If RowNames is not empty, then the number of character vectors must equal the number of rows in the table. MATLAB® removes any leading or trailing white space from the character vectors.

The row names are visible when you view the table. Furthermore, you can use the row names within parentheses or curly braces to access the table data.

Another way to access the row names is to use dot syntax and the name of the first dimension of the table.

Example

Create a table. Then add row names and access rows by their names.

load patients
T = table(Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);

Add row names using the Properties.RowNames property. By default, tables do not have row names, but you can add them at any time.

T.Properties.RowNames = LastName;
head(T,4)
ans=4×7 table
                 Gender     Age    Height    Weight    Smoker    Systolic    Diastolic
                ________    ___    ______    ______    ______    ________    _________

    Smith       'Male'      38       71       176      true        124          93    
    Johnson     'Male'      43       69       163      false       109          77    
    Williams    'Female'    38       64       131      false       125          83    
    Jones       'Female'    40       67       133      false       117          75    

Another way to access the row names is by using dot syntax with the name of the first dimension of the table. Display the first five row names.

T.Properties.DimensionNames
ans = 1×2 cell array
    {'Row'}    {'Variables'}

T.Row(1:5)
ans = 5×1 cell array
    {'Smith'   }
    {'Johnson' }
    {'Williams'}
    {'Jones'   }
    {'Brown'   }

Index into the table by row names.

T({'Smith','Williams'},:)
ans=2×7 table
                 Gender     Age    Height    Weight    Smoker    Systolic    Diastolic
                ________    ___    ______    ______    ______    ________    _________

    Smith       'Male'      38       71       176      true        124          93    
    Williams    'Female'    38       64       131      false       125          83    

Table description, specified as a character vector. This description is visible when using the summary function.

Example

Create a table. Modify the description of the table. Display a summary of the result.

load patients
T = table(Gender,Age,Height,Weight);
T.Properties.Description = 'Simulated patient data';
summary(T)
Description:  Simulated patient data

Variables:

    Gender: 100×1 cell array of character vectors

    Age: 100×1 double

        Values:

            Min        25  
            Median     39  
            Max        50  

    Height: 100×1 double

        Values:

            Min          60   
            Median       67   
            Max          72   

    Weight: 100×1 double

        Values:

            Min          111  
            Median     142.5  
            Max          202  

Additional table information, specified as an array. You can attach data of any kind to a table using this property.

Example

Create a table. Attach an anonymous function as a piece of user data that is associated with the table.

load patients
T = table(Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
formula = @(x) x.^2;
T.Properties.UserData = formula;
T.Properties
ans = struct with fields:
             Description: ''
                UserData: @(x)x.^2
          DimensionNames: {'Row'  'Variables'}
           VariableNames: {'Gender'  'Age'  'Height'  'Weight'  'Smoker'  'Systolic'  'Diastolic'}
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowNames: {}

Variable Metadata

Variable names, specified as a cell array of character vectors that are nonempty and distinct. Variable names must be valid MATLAB identifiers. You can determine valid variable names using the function isvarname. MATLAB removes any leading or trailing whitespace from the character vectors. The number of character vectors must equal the number of variables.

If you do not specify variable names, or you specify invalid identifiers, then MATLAB uses a cell array of N character vectors of the form {'Var1' ... 'VarN'} where N is the number of variables.

The variable names are visible when viewing the table and when using the summary function. Furthermore, you can use the variable names within parentheses, within curly braces, or with dot indexing to access table data.

Example

Create a table with default variable names. Then modify the names using the Properties.VariableNames property.

T = table({'M';'M';'F';'F';'F'},[38;43;38;40;49], ...
          [71;69;64;67;64],[176;163;131;133;119])
T=5×4 table
    Var1    Var2    Var3    Var4
    ____    ____    ____    ____

    'M'      38      71     176 
    'M'      43      69     163 
    'F'      38      64     131 
    'F'      40      67     133 
    'F'      49      64     119 

T.Properties.VariableNames = {'Gender','Age','Height','Weight'}
T=5×4 table
    Gender    Age    Height    Weight
    ______    ___    ______    ______

     'M'      38       71       176  
     'M'      43       69       163  
     'F'      38       64       131  
     'F'      40       67       133  
     'F'      49       64       119  

A fundamental way to display and modify variables is to access them by name using dot syntax.

T.Age
ans = 5×1

    38
    43
    38
    40
    49

T.Age(1) = 53
T=5×4 table
    Gender    Age    Height    Weight
    ______    ___    ______    ______

     'M'      53       71       176  
     'M'      43       69       163  
     'F'      38       64       131  
     'F'      40       67       133  
     'F'      49       64       119  

Variable descriptions, specified as a cell array of character vectors. This property can be an empty cell array, which is the default. If the cell array is not empty, then it must contain as many character vectors as there are variables. You can specify an individual empty character vector within the cell array for a variable that does not have a description.

The variable descriptions are visible when using the summary function.

Example

Create a table. Modify the variable descriptions. Display a summary of the result.

load patients
T = table(Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
T.Properties.VariableDescriptions = {'','','','', ...
                                     'Has the patient ever been a smoker', ...
                                     'Systolic Pressure','Diastolic Pressure'};
summary(T)
Variables:

    Gender: 100×1 cell array of character vectors

    Age: 100×1 double

        Values:

            Min        25  
            Median     39  
            Max        50  

    Height: 100×1 double

        Values:

            Min          60   
            Median       67   
            Max          72   

    Weight: 100×1 double

        Values:

            Min          111  
            Median     142.5  
            Max          202  

    Smoker: 100×1 logical

        Description:  Has the patient ever been a smoker
        Values:

            True        34   
            False       66   

    Systolic: 100×1 double

        Description:  Systolic Pressure
        Values:

            Min          109    
            Median       122    
            Max          138    

    Diastolic: 100×1 double

        Description:  Diastolic Pressure
        Values:

            Min            68    
            Median       81.5    
            Max            99    

Variable units, specified as a cell array of character vectors. This property can be an empty cell array, which is the default. If the cell array is not empty, then it must contain as many character vectors as there are variables. You can specify an individual empty character vector within the cell array for a variable that does not have units.

The variable units are visible when using the summary function.

Example

Create a table. Modify the variable units. Display a summary of the result.

load patients
T = table(Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
T.Properties.VariableUnits = {'','Yrs','In','Lbs','','mm Hg','mm Hg'};
summary(T)
Variables:

    Gender: 100×1 cell array of character vectors

    Age: 100×1 double

        Units:  Yrs
        Values:

            Min        25  
            Median     39  
            Max        50  

    Height: 100×1 double

        Units:  In
        Values:

            Min          60   
            Median       67   
            Max          72   

    Weight: 100×1 double

        Units:  Lbs
        Values:

            Min          111  
            Median     142.5  
            Max          202  

    Smoker: 100×1 logical

        Values:

            True        34   
            False       66   

    Systolic: 100×1 double

        Units:  mm Hg
        Values:

            Min          109    
            Median       122    
            Max          138    

    Diastolic: 100×1 double

        Units:  mm Hg
        Values:

            Min            68    
            Median       81.5    
            Max            99    

Examples

collapse all

Store data about a group of patients in a table. You can perform calculations and store results in the same table. Also, you can annotate the table to describe your work and the variables of the table.

First, create workspace variables that have the patient data. The variables can have any data types but must have the same number of rows.

LastName = {'Sanchez';'Johnson';'Li';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];

Create a table, T, as a container for the workspace variables. The table function uses the workspace variable names as the names of the table variables in T. A table variable can have multiple columns. For example, the BloodPressure variable in T is a 5-by-2 array.

T = table(LastName,Age,Smoker,Height,Weight,BloodPressure)
T=5×6 table
    LastName     Age    Smoker    Height    Weight    BloodPressure
    _________    ___    ______    ______    ______    _____________

    'Sanchez'    38     true        71       176       124     93  
    'Johnson'    43     false       69       163       109     77  
    'Li'         38     true        64       131       125     83  
    'Diaz'       40     false       67       133       117     75  
    'Brown'      49     true        64       119       122     80  

You can use dot indexing to access table variables. For example, calculate the mean height of the patients using the values in T.Height.

meanHeight = mean(T.Height)
meanHeight = 67

Calculate body mass index (BMI), and add it as a new table variable. You also can add and name table variables in one step, using dot syntax.

T.BMI = (T.Weight*0.453592)./(T.Height*0.0254).^2
T=5×7 table
    LastName     Age    Smoker    Height    Weight    BloodPressure     BMI  
    _________    ___    ______    ______    ______    _____________    ______

    'Sanchez'    38     true        71       176       124     93      24.547
    'Johnson'    43     false       69       163       109     77      24.071
    'Li'         38     true        64       131       125     83      22.486
    'Diaz'       40     false       67       133       117     75      20.831
    'Brown'      49     true        64       119       122     80      20.426

Annotate the table with a description of the BMI calculation. You can annotate T and its variables using metadata accessed through T.Properties.

T.Properties.Description = 'Patient data, including body mass index (BMI) calculated using Height and Weight';
T.Properties
ans = struct with fields:
             Description: 'Patient data, including body mass index (BMI) calculated using Height and Weight'
                UserData: []
          DimensionNames: {'Row'  'Variables'}
           VariableNames: {'LastName'  'Age'  'Smoker'  'Height'  'Weight'  'BloodPressure'  'BMI'}
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowNames: {}

Access all the data from a table as a matrix, using the name of the second dimension of the table.

Create a table that has five rows of data about a set of patients.

Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];

T = table(Age,Smoker,Height,Weight,BloodPressure)
T=5×5 table
    Age    Smoker    Height    Weight    BloodPressure
    ___    ______    ______    ______    _____________

    38     true        71       176       124     93  
    43     false       69       163       109     77  
    38     true        64       131       125     83  
    40     false       67       133       117     75  
    49     true        64       119       122     80  

Display the names of the table dimensions using the DimensionNames property. The default name of the second dimension is Variables.

T.Properties.DimensionNames
ans = 1×2 cell array
    {'Row'}    {'Variables'}

Access the table data as a matrix using the syntax T.Variables. This syntax is equivalent to accessing all the contents using curly brace syntax, T{:,:}. If the table data cannot be concatenated into a matrix, then an error message is raised.

T.Variables
ans = 5×6

    38     1    71   176   124    93
    43     0    69   163   109    77
    38     1    64   131   125    83
    40     0    67   133   117    75
    49     1    64   119   122    80

Rename the second dimension. If you change the name, then you can use the new name to access the data.

T.Properties.DimensionNames{2} = 'PatientData';
T.PatientData
ans = 5×6

    38     1    71   176   124    93
    43     0    69   163   109    77
    38     1    64   131   125    83
    40     0    67   133   117    75
    49     1    64   119   122    80

Preallocate a table by specifying its size and the data types of the variables. The table function fills the variables with default values that are appropriate for the data types you specify. It also gives the variables default names, but you also can assign variable names of your own. Preallocation provides room for data you add to the table later.

sz = [4 3];
varTypes = {'double','datetime','string'};
T = table('Size',sz,'VariableTypes',varTypes)
T=4×3 table
    Var1    Var2      Var3   
    ____    ____    _________

     0      NaT     <missing>
     0      NaT     <missing>
     0      NaT     <missing>
     0      NaT     <missing>

To specify names for the variables, use the 'VariableNames' name-value pair argument.

varNames = {'Temperature','Time','Station'};
T2 = table('Size',sz,'VariableTypes',varTypes,'VariableNames',varNames)
T2=4×3 table
    Temperature    Time     Station 
    ___________    ____    _________

         0         NaT     <missing>
         0         NaT     <missing>
         0         NaT     <missing>
         0         NaT     <missing>

Add rows of data to the first two rows of T2. Preallocation can be a useful technique when your code adds one row of data, or a few rows of data, at a time. Instead of growing the table every time you add a row, you can fill in table variables that already have room for your data.

T2(1,:) = {75,datetime('now'),"S1"};
T2(2,:) = {68,datetime('now')+1,"S2"}
T2=4×3 table
    Temperature       Time         Station 
    ___________    ___________    _________

        75         18-Jan-2018    "S1"     
        68         19-Jan-2018    "S2"     
         0                 NaT    <missing>
         0                 NaT    <missing>

You can encapsulate a row of data values in a cell array. When you assign a row from a cell array, elements from the cell array are assigned to the row in the table.

Create a table from arrays. To specify table variable names, use the 'VariableNames' name-value pair argument. For example, you can use 'VariableNames' to specify names when the other input arguments are not workspace variables.

T = table(categorical({'M';'F';'M'}),[45;32;34],...
          {'NY';'CA';'MA'},logical([1;0;0]),...
          'VariableNames',{'Gender','Age','State','Vote'})
T=3×4 table
    Gender    Age    State    Vote 
    ______    ___    _____    _____

      M       45     'NY'     true 
      F       32     'CA'     false
      M       34     'MA'     false

Create a table with the state names as row names. You can specify both the 'VariableNames' and 'RowNames' name-value pairs when using the table function.

T = table(categorical({'M';'F';'M'}),[45;32;34],logical([1;0;0]),...
          'VariableNames',{'Gender','Age','Vote'},...
          'RowNames',{'NY';'CA';'MA'})
T=3×3 table
          Gender    Age    Vote 
          ______    ___    _____

    NY      M       45     true 
    CA      F       32     false
    MA      M       34     false

Specify row names for a table. Tables do not have to have row names, but if you specify them, then you can index into a table by row name. You also can access the set of row names using the name of the first dimension of a table.

Create arrays containing patient data.

LastName = {'Sanchez';'Johnson';'Lee';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];

Create a table containing the arrays. Specify LastName as the source of row names for the table. The table has only three variables. The row names are not a table variable, but instead a property of the table.

T = table(Age,Weight,Height,'RowNames',LastName)
T=5×3 table
               Age    Weight    Height
               ___    ______    ______

    Sanchez    38      176        71  
    Johnson    43      163        69  
    Lee        38      131        64  
    Diaz       40      133        67  
    Brown      49      119        64  

Since the rows have row names, you can index into the rows of T by name.

T('Lee',:)
ans=1×3 table
           Age    Weight    Height
           ___    ______    ______

    Lee    38      131        64  

To specify multiple rows, use a cell array.

T({'Lee','Brown'},:)
ans=2×3 table
             Age    Weight    Height
             ___    ______    ______

    Lee      38      131        64  
    Brown    49      119        64  

To access all the row names of T as a cell array, use the syntax T.Row. By default, Row is the name of the first dimension of a table.

T.Row
ans = 5×1 cell array
    {'Sanchez'}
    {'Johnson'}
    {'Lee'    }
    {'Diaz'   }
    {'Brown'  }

Change the name of the first dimension. If you change the name, then you can access the row names using the new name.

T.Properties.DimensionNames{1} = 'LastNames';
T.LastNames
ans = 5×1 cell array
    {'Sanchez'}
    {'Johnson'}
    {'Lee'    }
    {'Diaz'   }
    {'Brown'  }

Starting in R2017a, you can create strings using double quotes, and add string arrays as table variables.

FlightNum = [1261;547;3489];
Customer = ["Jones";"Brown";"Smith"];
Date = datetime(2016,12,20:22)';
Rating = categorical(["Good";"Poor";"Fair"]);
Comment = ["Flight left on time, not crowded";...
           "Late departure, ran out of dinner options";...
           "Late, but only by half an hour. Otherwise fine."];
T = table(FlightNum,Customer,Date,Rating,Comment)
T=3×5 table
    FlightNum    Customer       Date        Rating                         Comment                     
    _________    ________    ___________    ______    _________________________________________________

      1261       "Jones"     20-Dec-2016     Good     "Flight left on time, not crowded"               
       547       "Brown"     21-Dec-2016     Poor     "Late departure, ran out of dinner options"      
      3489       "Smith"     22-Dec-2016     Fair     "Late, but only by half an hour. Otherwise fine."

To use the text in a string array as row names, convert the string array to a cell array of character vectors. Then create a table with row names.

Customer = cellstr(Customer);
T = table(FlightNum,Date,Rating,Comment,'RowNames',Customer)
T=3×4 table
             FlightNum       Date        Rating                         Comment                     
             _________    ___________    ______    _________________________________________________

    Jones      1261       20-Dec-2016     Good     "Flight left on time, not crowded"               
    Brown       547       21-Dec-2016     Poor     "Late departure, ran out of dinner options"      
    Smith      3489       22-Dec-2016     Fair     "Late, but only by half an hour. Otherwise fine."

Create workspace variables containing snowfall totals on different dates at three locations. These variables are row vectors.

Date = {'12/25/11','1/2/12','1/23/12','2/7/12','2/15/12'};
location1 = [20 5 13 0 17];
location2 = [18 9 21 5 12];
location3 = [26 10 16 3 15];

One way to create a table from these variables is to call the table function with the syntax T = table(Date',location1',location2',location3'). Because the workspace variables are row vectors, you must transpose them to put them into the table as column-oriented data. Therefore, the input arguments are expressions, not simple variables. As a result, table creates T with the default variable names Var1, Var2, Var3, and Var4. You can assign more meaningful names to T.Properties.VariableNames after you create T. But, it might be more convenient to create an empty table, and then add variables one at a time with new names.

Create an empty table. Transpose the workspace variables and add them to the table as column vectors. As part of assigning each workspace variable into T, provide a meaningful name for the table variable.

T = table;
T.Date = Date';
T.Natick = location1';
T.Boston = location2';
T.Worcester = location3'
T=5×4 table
       Date       Natick    Boston    Worcester
    __________    ______    ______    _________

    '12/25/11'      20        18         26    
    '1/2/12'         5         9         10    
    '1/23/12'       13        21         16    
    '2/7/12'         0         5          3    
    '2/15/12'       17        12         15    

Tips

  • For a list of functions that accept or return tables, see Tables.

Extended Capabilities

Introduced in R2013b

Was this topic helpful?