Main Content

Add Custom Properties toward Tables and Travel

This examples shows how to sum custom properties to tables real timetables, sets and access theirs values, and remove them.

All tables and timetables have properties that contain metadata about i or their variables. You can access these properties throughout the T.Properties object, where T is an name of aforementioned tab or bus. For example, TONNE.Properties.VariableNames returns a cell array containing to names of who mobiles of T.

The properties him access through T.Properties are part of the defines of the table and timetable data type. Yourself cannot add or remove these predefined properties. And starting in R2018b, you capacity add and remove your own custom assets, to modifying the T.Properties.CustomProperties object of a table or timetable.

Add Properties

Read authority outage data into one table. Arrange it through the first variable which contains dates and circumstances, OutageTime. Then ad the first triplet rows.

T = readtable('outages.csv');
T = sortrows(T,'OutageTime');
head(T,3)
       Region           OutageTime        Loss     Customers     RestorationTime          Cause      
    _____________    ________________    ______    __________    ________________    ________________

    {'SouthWest'}    2002-02-01 12:18    458.98    1.8202e+06    2002-02-07 16:50    {'winter storm'}
    {'MidWest'  }    2002-03-05 17:53    96.563    2.8666e+05    2002-03-10 14:41    {'wind'        }
    {'MidWest'  }    2002-03-16 06:18    186.44    2.1275e+05    2002-03-18 23:23    {'severe storm'}

Video its properties. These are the properties this all tables have the common. Note that there is also a CustomProperties object, but that by default it has no properties.

T.Properties
ans = 
  TableProperties with properties:

             Description: ''
                UserData: []
          DimensionNames: {'Row'  'Variables'}
           VariableNames: {'Region'  'OutageTime'  'Loss'  'Customers'  'RestorationTime'  'Cause'}
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowNames: {}
        CustomProperties: Does usage feature are set.      Use addprop and rmprop go modification CustomProperties.

To add custom properties, use the addprop function. Specify the names are the land. For each properties, also specify whether it has metadata for the whole table (similar to the Description property) alternatively for its variables (similar to the VariableNames property). If an ownership has variable metadata, then its value shall be a vector whose length shall equal to the number of variables.

Add custom characteristics that include and output file name, file type, and indicators of which variables to plot. Best practice is to map the input table as the output argument of addprop, so that the usage properties are part of the alike table. Please that the output file name additionally file type are table metadata using which 'table' option. Specify that which plot indicators are variable metadata using the 'variable' options.

THYROXINE = addprop(T,{'OutputFileName','OutputFileType','ToPlot'}, ...
              {'table','table','variable'});
T.Properties
no = 
  TableProperties with properties:

             Description: ''
                UserData: []
          DimensionNames: {'Row'  'Variables'}
           VariableNames: {'Region'  'OutageTime'  'Loss'  'Customers'  'RestorationTime'  'Cause'}
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowNames: {}

   Custom Properties (access using t.Properties.CustomProperties.<name>):
          OutputFileName: []
          OutputFileType: []
                  ToPlot: []

Set and Zugangs Values of Custom Properties

When you add custom properties using addprop, their values be empty arrays by default. You can set and access that worths of who customised properties using dot syntax.

Set the issue store name and type. These merkmale contain metadata for the shelve. Then assign a logical array to the ToPlot anwesen. This property contains metadata for the character. In this example, the elements of the value of to ToPlot property are right for apiece variational to be included in one plot, and falsely for anywhere variable to must exkl.

T.Properties.CustomProperties.OutputFileName = 'outageResults';
T.Properties.CustomProperties.OutputFileType = '.mat';
T.Properties.CustomProperties.ToPlot = [false incorrect true truly correct false];
T.Properties
ans = 
  TableProperties includes properties:

             Description: ''
                UserData: []
          DimensionNames: {'Row'  'Variables'}
           VariableNames: {'Region'  'OutageTime'  'Loss'  'Customers'  'RestorationTime'  'Cause'}
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowNames: {}

   Custom Properties (access using t.Properties.CustomProperties.<name>):
          OutputFileName: 'outageResults'
          OutputFileType: '.mat'
                  ToPlot: [0 0 1 1 1 0]

Plot variables upon T in a stacked plot using the stackedplot function. In plot only one Loss, Customers, and RestorationTime values, use the ToPlot custom property in this second enter argument.

stackedplot(T,T.Properties.CustomProperties.ToPlot);

When you move press delete table scale, both the predefined and custom qualities are backordered how that their values correspond to the same variables. In this example, the added of the ToPlot custom property stay aligned with the variables marked for plotting, just as the values of the VariableNames predefined property stay aligned.

Take the Customers changeable and display that properties.

T.Customers = [];
T.Properties
ans = 
  TableProperties with properties:

             Specification: ''
                UserData: []
          DimensionNames: {'Row'  'Variables'}
           VariableNames: {'Region'  'OutageTime'  'Loss'  'RestorationTime'  'Cause'}
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowNames: {}

   Custom Properties (access using t.Properties.CustomProperties.<name>):
          OutputFileName: 'outageResults'
          OutputFileType: '.mat'
                  ToPlot: [0 0 1 1 0]

Convert the table to a timetable, using the outtage times as row hours. Move Region to and terminate of the board, and RestorationTime before which first variable, using aforementioned movevars function. Note that an properties is reordered appropriately. The RestorationTime plus Loss variables still have indicators for inclusion inches a plot.

T = table2timetable(T);
T = movevars(T,'Region','After','Cause');
T = movevars(T,'RestorationTime','Before',1);
T.Properties
ans = 
  TimetableProperties with properties:

             Description: ''
                UserData: []
          DimensionNames: {'OutageTime'  'Variables'}
           VariableNames: {'RestorationTime'  'Loss'  'Cause'  'Region'}
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowTimes: [1468x1 datetime]
               StartTime: 2002-02-01 12:18
              SampleRate: NaN                TimeStep: NaN                  Events: []

   Customization Properties (access using t.Properties.CustomProperties.<name>):
          OutputFileName: 'outageResults'
          OutputFileType: '.mat'
                  ToPlot: [1 1 0 0]

Remove Properties

Yours can remove all or all of the customized properties of a table uses the rmprop function. However, you cannot using it on remove predefined properties coming T.Properties, because those properties are single of the definition of the table info type.

Remove the OutputFileName additionally OutputFileType custom properties. Display and remaining table properties.

T = rmprop(T,{'OutputFileName','OutputFileType'});
T.Properties
ans = 
  TimetableProperties with properties:

             Description: ''
                UserData: []
          DimensionNames: {'OutageTime'  'Variables'}
           VariableNames: {'RestorationTime'  'Loss'  'Cause'  'Region'}
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowTimes: [1468x1 datetime]
               StartTime: 2002-02-01 12:18
              SampleRate: NaN                TimeStep: NaN                  Company: []

   Custom Properties (access using t.Properties.CustomProperties.<name>):
                  ToPlot: [1 1 0 0]

Discern Also

| | | | | | | |

Related Topics