Documentation Center

  • Trial Software
  • Product Updates

table2dataset

Convert table to dataset array

The dataset data type might be removed in a future release. To work with heterogeneous data, use the MATLAB® table data type instead. See MATLAB table documentation for more information.

Syntax

Description

example

ds = table2dataset(t) converts a table to a dataset array.

Examples

expand all

Convert a Table to a Dataset Array

Load the sample data, which contains nutritional information for 77 cereals.

load cereal;

Create a table containing the calorie, protein, fat, and name data for the first five cereals. Label the variables.

Calories = Calories(1:5);
Protein = Protein(1:5);
Fat = Fat(1:5);
Name = Name(1:5);

cereal = table(Calories,Protein,Fat,'RowNames',Name)
cereal = 

                                 Calories    Protein    Fat
                                 --------    -------    ---
    100% Bran                     70         4          1  
    100% Natural Bran            120         3          5  
    All-Bran                      70         4          1  
    All-Bran with Extra Fiber     50         4          0  
    Almond Delight               110         2          2  

Convert the table to a dataset array.

ds = table2dataset(cereal)
ds = 

                                 Calories    Protein    Fat
    100% Bran                     70         4          1  
    100% Natural Bran            120         3          5  
    All-Bran                      70         4          1  
    All-Bran with Extra Fiber     50         4          0  
    Almond Delight               110         2          2  

Input Arguments

expand all

t — Input tabletable

Input table to convert to a dataset array, specified as a table. Each variable in t becomes a variable in the output dataset array ds.

Example:

Data Types: table

Output Arguments

expand all

ds — Output dataset arraydataset array

Output dataset array, returned as a dataset array containing the variables from the input table t.

See Also

|

Was this topic helpful?