主要内容

使用 MDF 事件

此示例说明如何从 MDF 文件中读取事件并使用事件过滤数据。

查看 MDF 文件中的所有事件

使用 mdfInfo 与文件名查看 MDF 文件的元数据和事件。

fileInfo = mdfInfo("VehicleDataWithEvents.mf4")
fileInfo = 
  MDFInfo with properties:

   File Details
                  Name: "VehicleDataWithEvents.mf4"
                  Path: "/tmp/Bdoc25b_2988451_1430519/tpe4ace63d/vnt-ex41269135/VehicleDataWithEvents.mf4"
                Author: ""
            Department: ""
               Project: ""
               Subject: ""
               Comment: "Example file demonstrating workflows of reading events."
               Version: "4.10"
      InitialTimestamp: 2024-04-23 18:35:45.000000000

   Creator Details
     ProgramIdentifier: "MDF4Lib"
     CreatorVendorName: ""
       CreatorToolName: ""
    CreatorToolVersion: "1.0"
       CreatorUserName: ""
        CreatorComment: "created"

   File Contents
            Attachment: [0×7 table]
     ChannelGroupCount: 2
                 Event: [8×8 eventtable]

Event 属性包含 MDF 文件中所有事件的事件表。

fileEvents = fileInfo.Event
fileEvents = 8×8 eventtable
  Event Labels Variable: Name
  Event Lengths Variable: <instantaneous>

      Time            Name                                  Comment                                    Type           Cause      ScopeType      GroupNumber    RangeType    LinkAddress
    ________    ________________    ________________________________________________________    __________________    ______    ____________    ___________    _________    ___________

    0 sec       "USER COMMENT"      "Logging Vehicle Data 12/24/23"                             Marker                User      File                NaN          Point       ""        
    1 sec       "REC BEGIN"         "Recording has started successfully."                       Recording             Tool      File                NaN          Begin       "0x1C80"  
    1.2 sec     "REC INTERRUPT"     "Recording was interrupted."                                RecordingInterrupt    Script    ChannelGroup          1          Point       ""        
    8.5 sec     "USER REC BEGIN"    "User-initiated subrecording start."                        Recording             User      ChannelGroup          1          Begin       "0x1EC8"  
    10 sec      "TIME TRIGGER"      "Time min threshold trigger of 10 seconds has been hit."    Trigger               Script    ChannelGroup          2          Point       ""        
    11.5 sec    "USER REC END"      "User-initiated subrecording end."                          Recording             User      ChannelGroup          1          End         "0x1EC8"  
    14.1 sec    "RPM TRIGGER"       "RPM max threshold trigger of 1500 has been hit."           Trigger               Script    ChannelGroup          1          Point       ""        
    15 sec      "REC END"           "Recording has stopped successfully."                       Recording             Tool      File                NaN          End         "0x1C80"  

每个事件都有一个时间戳和 8 个元数据值。

  • ScopeType 值表示事件是应用于特定通道组还是应用于整个文件。

  • GroupNumber 值表示事件作用域限于的特定通道组。

  • 事件可以在某个时间点发生,也可以在一段时间内发生。RangeType 值表示事件是发生在某个时间点,标记范围的开始,还是标记范围的结束。

  • LinkAddress 值用于链接对应的范围事件。一对开始和结束范围事件共用相同的 LinkAddress 值,该值表示开始事件的地址。

从 MDF 文件中读取所有数据和事件

从 MDF 文件中读取所有数据和事件的最简单方法是只使用文件名调用 mdfRead 函数。每个时间表表示从对应的通道组读取的数据。每个时间表包含一个事件表,该事件表表示作用域限于对应通道组的文件级事件和通道组级事件。

data = mdfRead("VehicleDataWithEvents.mf4")
data=2×1 cell array
    {160×3 timetable}
    { 16×3 timetable}

data{1}
ans=160×3 timetable with 7 events
                        t       EngineRPM    Throttle    OutputTorque
                     _______    _________    ________    ____________

    USER COMMENT     0 sec          41            7           34     
                     0.1 sec        10          9.5           25     
                     0.2 sec        98            9           14     
                     0.3 sec        94          6.5           48     
                     0.4 sec       121            9           15     
                     0.5 sec       141          7.5           47     
                     0.6 sec        87            9           47     
                     0.7 sec        74          5.5           10     
                     0.8 sec       172            6           29     
                     0.9 sec       106         12.5           54     
    REC BEGIN        1 sec         147           11           31     
                     1.1 sec       148         14.5           23     
    REC INTERRUPT    1.2 sec       187           15           47     
                     1.3 sec       224          9.5           24     
                     1.4 sec       162           10           37     
                     1.5 sec       214          8.5           26     
      ⋮

通过访问时间表的 Events 属性来检索附加到时间表的事件。

chanGrp1Events = data{1}.Properties.Events
chanGrp1Events = 7×8 eventtable
  Event Labels Variable: Name
  Event Lengths Variable: <instantaneous>

      Time            Name                               Comment                                Type           Cause      ScopeType      GroupNumber    RangeType    LinkAddress
    ________    ________________    _________________________________________________    __________________    ______    ____________    ___________    _________    ___________

    0 sec       "USER COMMENT"      "Logging Vehicle Data 12/24/23"                      Marker                User      File                NaN          Point       ""        
    1 sec       "REC BEGIN"         "Recording has started successfully."                Recording             Tool      File                NaN          Begin       "0x1C80"  
    1.2 sec     "REC INTERRUPT"     "Recording was interrupted."                         RecordingInterrupt    Script    ChannelGroup          1          Point       ""        
    8.5 sec     "USER REC BEGIN"    "User-initiated subrecording start."                 Recording             User      ChannelGroup          1          Begin       "0x1EC8"  
    11.5 sec    "USER REC END"      "User-initiated subrecording end."                   Recording             User      ChannelGroup          1          End         "0x1EC8"  
    14.1 sec    "RPM TRIGGER"       "RPM max threshold trigger of 1500 has been hit."    Trigger               Script    ChannelGroup          1          Point       ""        
    15 sec      "REC END"           "Recording has stopped successfully."                Recording             Tool      File                NaN          End         "0x1C80"  

data{2}
ans=16×3 timetable with 4 events
                      t       VehicleSpeed    Brake    Gear
                    ______    ____________    _____    ____

    USER COMMENT    0 sec          82           0       1  
    REC BEGIN       1 sec          97           1       2  
                    2 sec          45           1       1  
                    3 sec          58           1       0  
                    4 sec          42           0       3  
                    5 sec         146           1       1  
                    6 sec         155           1       0  
                    7 sec         130           0       0  
                    8 sec         110           0       3  
                    9 sec         161           1       3  
    TIME TRIGGER    10 sec        153           0       2  
                    11 sec        134           0       3  
                    12 sec        160           1       2  
                    13 sec        159           0       1  
                    14 sec        198           0       1  
    REC END         15 sec        157           1       0  

chanGrp2Events = data{2}.Properties.Events
chanGrp2Events = 4×8 eventtable
  Event Labels Variable: Name
  Event Lengths Variable: <instantaneous>

     Time          Name                                 Comment                               Type       Cause      ScopeType      GroupNumber    RangeType    LinkAddress
    ______    ______________    ________________________________________________________    _________    ______    ____________    ___________    _________    ___________

    0 sec     "USER COMMENT"    "Logging Vehicle Data 12/24/23"                             Marker       User      File                NaN          Point       ""        
    1 sec     "REC BEGIN"       "Recording has started successfully."                       Recording    Tool      File                NaN          Begin       "0x1C80"  
    10 sec    "TIME TRIGGER"    "Time min threshold trigger of 10 seconds has been hit."    Trigger      Script    ChannelGroup          2          Point       ""        
    15 sec    "REC END"         "Recording has stopped successfully."                       Recording    Tool      File                NaN          End         "0x1C80"  

使用事件过滤数据

要基于事件过滤 MDF 数据,请使用 eventfilter。创建通道组 1 数据的子集,其中包含与某事件共享时间戳的采样。

EF = eventfilter(data{1})
EF = 
  eventfilter with no constraints and no selected variables

    <unconstrained>

  VariableNames: Time, Name, Comment, Type, Cause, ScopeType, GroupNumber, Range…

dataFilteredToEventTimestamps = data{1}(EF, :)
dataFilteredToEventTimestamps=7×3 timetable with 7 events
                         t        EngineRPM    Throttle    OutputTorque
                      ________    _________    ________    ____________

    USER COMMENT      0 sec           41            7           34     
    REC BEGIN         1 sec          147           11           31     
    REC INTERRUPT     1.2 sec        187           15           47     
    USER REC BEGIN    8.5 sec        896         44.5          121     
    USER REC END      11.5 sec      1158         59.5          160     
    RPM TRIGGER       14.1 sec      1503         75.5          172     
    REC END           15 sec        1519           80          176     

创建通道组 1 数据的子集,其中包含用户启动的记录开始事件和用户启动的记录结束事件之间的采样。

TR = timerange(EF.Name == "USER REC BEGIN", EF.Name == "USER REC END")
TR = 
	timetable timerange subscript:

		Select timetable rows with event times in the half-open interval:
		  Starting at, including:   Name == "USER REC BEGIN"
		  Ending at, but excluding: Name == "USER REC END"

	See Select Times in Timetable.

dataFilteredToUserRecEventTimeRange = data{1}(TR, :)
dataFilteredToUserRecEventTimeRange=30×3 timetable with 7 events
                         t       EngineRPM    Throttle    OutputTorque
                      _______    _________    ________    ____________

    USER REC BEGIN    8.5 sec       896         44.5          121     
                      8.6 sec       935           46          105     
                      8.7 sec       912         47.5          103     
                      8.8 sec       961           52          110     
                      8.9 sec       941         45.5          138     
                      9 sec         957           51          132     
                      9.1 sec       999         50.5          103     
                      9.2 sec       920           46           95     
                      9.3 sec       999         47.5          131     
                      9.4 sec       941           56           99     
                      9.5 sec       973         49.5          130     
                      9.6 sec      1042           53          134     
                      9.7 sec       996         55.5          104     
                      9.8 sec      1012           51          117     
                      9.9 sec      1044         50.5          138     
                      10 sec       1076           59          118     
      ⋮

可视化包含事件的数据

使用 stackedplot 可视化 MDF 数据,其中事件标记为垂直线。

stackedplot(data{1})

Figure contains an object of type stackedplot.

另请参阅

函数