Contenido principal

labels

R2026b

Create subscript to access timetable data

Since R2026b

    Description

    S = labels(lbls) creates a subscript to select rows of a timetable. The subscript S selects timetable rows whose row-time values match the values in lbls. Use this function to distinguish numeric row-time values from row positional indices when subscripting into a timetable.

    example

    Examples

    collapse all

    Create a timetable with numeric row times that represent days of the year.

    DayOfYear = [1; 3; 236];
    Temp = [37.3; 39.1; 42.3];
    Pressure = [29.4; 29.6; 30.0];
    TT = timetable(Temp,Pressure,RowTimes=DayOfYear)
    
    TT =
    
      3×2 timetable
    
        Time    Temp    Pressure
        ____    ____    ________
    
        1       37.3      29.4  
        3       39.1      29.6  
        236     42.3        30     

    Select the row with day value 3 using labels.

    r1 = TT(labels(3),:)
    r1 =
    
      1×2 timetable
    
        Time    Temp    Pressure
        ____    ____    ________
    
        3       39.1      29.6    

    In contrast, TT(3,:) returns the third row of TT.

    r2 = TT(3,:)
    r2 =
    
      1×2 timetable
    
        Time    Temp    Pressure
        ____    ____    ________
    
        236     42.3       30   
     

    Input Arguments

    collapse all

    Values to match the row times of a timetable, specified as a datetime array, duration array, double array, or single array. Specify lbls using values that exactly match the row-time values of rows that you want to select from a timetable.

    If lbls is a numeric array, then its elements specify numeric (double or single) row-time values, rather than positional indices. The resulting subscript S selects rows whose row-time values match those in lbls.

    Output Arguments

    collapse all

    Subscript to select rows, returned as a timetable subscript. Use S to select rows from a timetable whose row-time values match the specified lbls.

    Version History

    Introduced in R2026b