主要内容

timetable2table

将时间表转换为表

说明

T = timetable2table(TT)M×N 时间表 TT 转换为 M×(N+1) 表。TT 中的行时间向量成为 T 中的第一个变量。

该转换会丢弃属性 RowTimesStartTimeSampleRateTimeStepEvents,因为它们仅是时间表的属性。转换后保留的属性是表和表时间表共有的属性。

要将时间表写为文本文件或电子表格文件,请使用 writetimetable 函数。

示例

T = timetable2table(TT,ConvertRowTimes=false) 丢弃来自 TT 的行时间向量。

示例

示例

全部折叠

创建一个时间表。

Time = datetime(["2025-12-18";"2025-12-19";"2025-12-20"]);
Temp = [37.3;39.1;42.3];
Pressure = [29.4;29.6;30.0];
Precip = [0.1;0.9;0.0];
TT = timetable(Time,Temp,Pressure,Precip)
TT=3×3 timetable
       Time        Temp    Pressure    Precip
    ___________    ____    ________    ______

    18-Dec-2025    37.3      29.4       0.1  
    19-Dec-2025    39.1      29.6       0.9  
    20-Dec-2025    42.3        30         0  

TT 转换为表。来自时间表的行时间向量成为输出表的一个变量。因此,当时间表具有一个行时间向量和三个变量时,表具有四个变量。

T = timetable2table(TT)
T=3×4 table
       Time        Temp    Pressure    Precip
    ___________    ____    ________    ______

    18-Dec-2025    37.3      29.4       0.1  
    19-Dec-2025    39.1      29.6       0.9  
    20-Dec-2025    42.3        30         0  

显示输入时间表的属性。由于时间表是表的一种类型,它具有表所具有的属性,例如 VariableNames。但它也具有仅与时间表相关的属性,例如 RowTimes

TT.Properties
ans = 
  TimetableProperties with properties:

             Description: ''
                UserData: []
          DimensionNames: {'Time'  'Variables'}
           VariableNames: {'Temp'  'Pressure'  'Precip'}
           VariableTypes: ["double"    "double"    "double"]
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowTimes: [3×1 datetime]
               StartTime: 18-Dec-2025
              SampleRate: NaN
                TimeStep: 1d
                  Events: []
        CustomProperties: No custom properties are set.
      Use addprop and rmprop to modify CustomProperties.

显示输出表的属性。timetable2table 函数丢弃 RowTimesStartTimeSampleRateTimeStepEvents 属性。

T.Properties
ans = 
  TableProperties with properties:

             Description: ''
                UserData: []
          DimensionNames: {'Row'  'Variables'}
           VariableNames: {'Time'  'Temp'  'Pressure'  'Precip'}
           VariableTypes: ["datetime"    "double"    "double"    "double"]
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowNames: {}
        CustomProperties: No custom properties are set.
      Use addprop and rmprop to modify CustomProperties.

创建一个时间表。

Time = datetime(["2025-12-18";"2025-12-19";"2025-12-20"]);
Temp = [37.3;39.1;42.3];
Pressure = [29.4;29.6;30.0];
Precip = [0.1;0.9;0.0];
TT = timetable(Time,Temp,Pressure,Precip)
TT=3×3 timetable
       Time        Temp    Pressure    Precip
    ___________    ____    ________    ______

    18-Dec-2025    37.3      29.4       0.1  
    19-Dec-2025    39.1      29.6       0.9  
    20-Dec-2025    42.3        30         0  

TT 转换为表并丢弃其行时间。

T = timetable2table(TT,ConvertRowTimes=false)
T=3×3 table
    Temp    Pressure    Precip
    ____    ________    ______

    37.3      29.4       0.1  
    39.1      29.6       0.9  
    42.3        30         0  

输入参数

全部折叠

输入时间表。

输出参量

全部折叠

输出表。该表仅保留表和表时间表共有的属性,例如描述、变量单位和变量名称。有关详细信息,请比较 tabletimetable 的“属性”部分。

扩展功能

全部展开

基于线程的环境
使用 MATLAB® backgroundPool 在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool 加快代码运行速度。

版本历史记录

在 R2016b 中推出