メインコンテンツ

このページは機械翻訳を使用して翻訳されました。最新版の英語を参照するには、ここをクリックします。

既存の MDF ファイルから新しい MDF ファイルにチャネル グループ データを書き込む

この例では、MDF ファイルのチャネル グループに記録されたデータを処理し、更新されたデータを新しいファイルに書き込む方法を示します。この例で使用されている MDF ファイル VehicleData.mf4 には、2 つのチャネル グループの 2 つのシミュレーションから記録されたデータが含まれていますが、この例はチャネル グループ 2 のデータでのみ機能します。

まず、チャネル グループ 2 から timetable にデータを読み取り、次にデータのコピーに対して後処理を実行します。最後に、VehicleData.mf4 と同じファイル メタデータを持つ新しい MDF ファイルを作成し、更新されたデータを新しいチャネル グループとして新しい MDF ファイルに書き込みます。

MDF ファイルとそのチャネル グループの詳細を表示する

ファイル名を指定して、mdfInfo を使用してファイル VehicleData.mf4 のメタデータを表示します。

mdfInfo("VehicleData.mf4")
ans = 
  MDFInfo with properties:

   File Details
                  Name: "VehicleData.mf4"
                  Path: "/tmp/Bdoc25a_2864802_1974203/tp6f7be44e/vnt-ex28629694/VehicleData.mf4"
                Author: "Engineer"
            Department: "Automotive"
               Project: "Demo"
               Subject: "Prototype"
               Comment: "Example file"
               Version: "4.20"
      InitialTimestamp: 2024-11-14 19:16:35.000000000

   Creator Details
     ProgramIdentifier: "MATLAB"
     CreatorVendorName: "The MathWorks, Inc."
       CreatorToolName: "MATLAB"
    CreatorToolVersion: "25.1.0.2768609 (R2025a) Prerelease"
       CreatorUserName: "engineer"
        CreatorComment: "Created with Vehicle Network Toolbox"

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

mdfChannelGroupInfo を使用して 2 つのチャネル グループの詳細を調べます。

mdfChannelGroupInfo("VehicleData.mf4")
ans=2×13 table
    GroupNumber    AcquisitionName                                      Comment                                      NumSamples    DataSize    Sorted    SourceName     SourcePath     SourceComment    SourceType     SourceBusType    SourceBusChannelNumber    SourceSimulated
    ___________    _______________    ___________________________________________________________________________    __________    ________    ______    ___________    ___________    _____________    ___________    _____________    ______________________    _______________

         1           <undefined>      Simulation of an automatic transmission controller during passing maneuver.        751         43558     true      <undefined>    <undefined>     <undefined>     Unspecified     Unspecified               0                    false     
         2           <undefined>      Simulation of engine gas dynamics.                                               92033       2208792     true      <undefined>    <undefined>     <undefined>     Unspecified     Unspecified               0                    false     

メタデータを含むチャネル グループ データの読み取り

オプション引数 IncludeMetadatatrue に設定した mdfRead 関数を使用して、チャネル グループ 2 からデータを読み取ります。出力 timetable chanGrp2TT は、チャネル グループ 2 内のすべてのチャネルのデータのコピーです。

chanGrp2Data = mdfRead("VehicleData.mf4", GroupNumber=2, IncludeMetadata=true)
chanGrp2Data = 1×1 cell array
    {92033×2 timetable}

chanGrp2TT = chanGrp2Data{1}
chanGrp2TT=92033×2 timetable
             time         AirFlow    FuelRate
        ______________    _______    ________

        0 sec             17.294       1.209 
        0.00056199 sec    17.263       1.209 
        0.0033719 sec     17.112       1.209 
        0.01 sec          16.776      1.1729 
        0.02 sec          16.316      1.1409 
        0.03 sec          15.907      1.1124 
        0.04 sec          15.546      1.0873 
        0.05 sec          15.228      1.0652 
        0.055328 sec      15.075      1.0652 
        0.055328 sec      15.075      1.0652 
        0.055328 sec      15.075      1.0652 
        0.06 sec          14.949      1.0458 
        0.064672 sec      14.832      1.0458 
        0.07 sec          14.707      1.0289 
        0.08 sec          14.497      1.0143 
        0.09 sec          14.317      1.0019 
      ⋮

チャネル グループ 2 とそのチャネルのメタデータは、timetable でカスタム プロパティとして使用できます。チャネル グループのメタデータは、table 全体の timetable のカスタム プロパティとして保存され、プロパティ名には「ChannelGroup」というプレフィックスが付きます。個々のチャネルのメタデータは、変数の timetable のカスタム プロパティとして保存され、プロパティ名には「Channel」というプレフィックスが付きます。

チャネル グループ 2 およびこのグループ内のすべてのチャネルのメタデータを表示します。

chanGrp2TT.Properties.CustomProperties
ans = 
CustomProperties with properties:

                              Validity: [92033×2 timetable]
           ChannelGroupAcquisitionName: ""
                   ChannelGroupComment: "Simulation of engine gas dynamics."
                ChannelGroupSourceName: ""
                ChannelGroupSourcePath: ""
             ChannelGroupSourceComment: ""
                ChannelGroupSourceType: Unspecified
             ChannelGroupSourceBusType: Unspecified
    ChannelGroupSourceBusChannelNumber: 0
                    ChannelDisplayName: [""    ""]
                        ChannelComment: [""    ""]
                           ChannelUnit: ["g/s"    "g/s"]
                           ChannelType: [FixedLength    FixedLength]
                       ChannelDataType: [RealLittleEndian    RealLittleEndian]
                        ChannelNumBits: [64 64]
                  ChannelComponentType: [None    None]
                ChannelCompositionType: [None    None]
                     ChannelSourceName: [""    ""]
                     ChannelSourcePath: [""    ""]
                  ChannelSourceComment: [""    ""]
                     ChannelSourceType: [Unspecified    Unspecified]
                  ChannelSourceBusType: [Unspecified    Unspecified]
         ChannelSourceBusChannelNumber: [0 0]
                     ChannelReadOption: [All    All]

mdfRead 関数を呼び出す場合、IncludeMetadata はデフォルトで false に設定されることに注意してください。チャネル グループ データの読み取りの最終目的が、チャネル グループとチャネル メタデータを引き継いだ新しいチャネル グループに書き込むことである場合は、IncludeMetadatatrue に設定する必要があります。

データコピーのサンプル数を減らす

stackedplot を使用して積み重ねプロットを作成し、チャネル AirFlow および FuelRate のデータを可視化します。

stackedplot(chanGrp2TT, ["AirFlow", "FuelRate"])

Figure contains an object of type stackedplot.

積み重ねプロットから、FuelRate の値が 182.17 秒頃から 900 秒の記録終了まで 0 のままであることがわかります。これは、測定中に障害が発生した可能性があることを示しています。この特定のアプリケーションでは、FuelRate の値が無効な場合、記録された AirFlow の値は役に立ちません。したがって、FuelRate がゼロである無効なデータ サンプルを破棄することにします。

有効なゼロ以外の値のみを保持するように、チャネル グループ 2 のデータ サンプルを減らします。

chanGrp2TT = chanGrp2TT(chanGrp2TT.FuelRate ~= 0, :)
chanGrp2TT=18634×2 timetable
             time         AirFlow    FuelRate
        ______________    _______    ________

        0 sec             17.294       1.209 
        0.00056199 sec    17.263       1.209 
        0.0033719 sec     17.112       1.209 
        0.01 sec          16.776      1.1729 
        0.02 sec          16.316      1.1409 
        0.03 sec          15.907      1.1124 
        0.04 sec          15.546      1.0873 
        0.05 sec          15.228      1.0652 
        0.055328 sec      15.075      1.0652 
        0.055328 sec      15.075      1.0652 
        0.055328 sec      15.075      1.0652 
        0.06 sec          14.949      1.0458 
        0.064672 sec      14.832      1.0458 
        0.07 sec          14.707      1.0289 
        0.08 sec          14.497      1.0143 
        0.09 sec          14.317      1.0019 
      ⋮

データコピーにチャネルを追加する

空気流量を燃料率で割って空燃比を取得し、計算された値を AirFuelRatio という名前の新しい timetable 変数に割り当てます。

chanGrp2TT.AirFuelRatio = chanGrp2TT.AirFlow./chanGrp2TT.FuelRate
chanGrp2TT=18634×3 timetable
             time         AirFlow    FuelRate    AirFuelRatio
        ______________    _______    ________    ____________

        0 sec             17.294       1.209        14.304   
        0.00056199 sec    17.263       1.209        14.278   
        0.0033719 sec     17.112       1.209        14.154   
        0.01 sec          16.776      1.1729        14.303   
        0.02 sec          16.316      1.1409        14.301   
        0.03 sec          15.907      1.1124          14.3   
        0.04 sec          15.546      1.0873        14.298   
        0.05 sec          15.228      1.0652        14.296   
        0.055328 sec      15.075      1.0652        14.152   
        0.055328 sec      15.075      1.0652        14.152   
        0.055328 sec      15.075      1.0652        14.152   
        0.06 sec          14.949      1.0458        14.294   
        0.064672 sec      14.832      1.0458        14.182   
        0.07 sec          14.707      1.0289        14.293   
        0.08 sec          14.497      1.0143        14.292   
        0.09 sec          14.317      1.0019         14.29   
      ⋮

更新されたチャネル メタデータを検査し、新しく追加されたチャネルの missing 値をメモします。

chanGrp2TT.Properties.CustomProperties
ans = 
CustomProperties with properties:

                              Validity: [92033×2 timetable]
           ChannelGroupAcquisitionName: ""
                   ChannelGroupComment: "Simulation of engine gas dynamics."
                ChannelGroupSourceName: ""
                ChannelGroupSourcePath: ""
             ChannelGroupSourceComment: ""
                ChannelGroupSourceType: Unspecified
             ChannelGroupSourceBusType: Unspecified
    ChannelGroupSourceBusChannelNumber: 0
                    ChannelDisplayName: [""    ""    <missing>]
                        ChannelComment: [""    ""    <missing>]
                           ChannelUnit: ["g/s"    "g/s"    <missing>]
                           ChannelType: [FixedLength    FixedLength    Missing]
                       ChannelDataType: [RealLittleEndian    RealLittleEndian    Missing]
                        ChannelNumBits: [64 64 NaN]
                  ChannelComponentType: [None    None    Missing]
                ChannelCompositionType: [None    None    Missing]
                     ChannelSourceName: [""    ""    <missing>]
                     ChannelSourcePath: [""    ""    <missing>]
                  ChannelSourceComment: [""    ""    <missing>]
                     ChannelSourceType: [Unspecified    Unspecified    Missing]
                  ChannelSourceBusType: [Unspecified    Unspecified    Missing]
         ChannelSourceBusChannelNumber: [0 0 0]
                     ChannelReadOption: [All    All    Missing]

チャネルグループメタデータとチャネルメタデータをカスタマイズする

チャネル グループのコメントを更新して、データに対して行われた処理に関する情報を提供します。

chanGrpComment = chanGrp2TT.Properties.CustomProperties.ChannelGroupComment
chanGrpComment = 
"Simulation of engine gas dynamics."
chanGrp2TT.Properties.CustomProperties.ChannelGroupComment = chanGrpComment + " Update: Removed invalid samples and added new channel ""AirFuelRatio"".";

AirFlow および FuelRate のチャネルコメントを更新して、チャネルに関する詳細情報を提供します。ChannelComment メタデータにインデックスを付けるには、変数インデックスまたは変数名のいずれかを使用できます。

chanGrp2TT.Properties.CustomProperties.ChannelComment(1) = "Air flow logged from simulation.";
chanGrp2TT.Properties.CustomProperties.ChannelComment("FuelRate") = "Fuel rate logged from simulation.";

AirFuelRatio のチャネル コメントを追加します。

chanGrp2TT.Properties.CustomProperties.ChannelComment(3) = "Air fuel ratio calculated by dividing air flow by fuel rate.";

チャネル メタデータを調べて、ChannelGroupCommentChannelComment の更新された値をメモします。特定のメタデータをカスタマイズする必要がない場合は、missing 値をそのままにしておいても問題ありません。後で MDF ファイルに書き込むときに、それに応じてデフォルト値または派生値が適用されます。

chanGrp2TT.Properties.CustomProperties
ans = 
CustomProperties with properties:

                              Validity: [92033×2 timetable]
           ChannelGroupAcquisitionName: ""
                   ChannelGroupComment: "Simulation of engine gas dynamics. Update: Removed invalid samples and added new channel "AirFuelRatio"."
                ChannelGroupSourceName: ""
                ChannelGroupSourcePath: ""
             ChannelGroupSourceComment: ""
                ChannelGroupSourceType: Unspecified
             ChannelGroupSourceBusType: Unspecified
    ChannelGroupSourceBusChannelNumber: 0
                    ChannelDisplayName: [""    ""    <missing>]
                        ChannelComment: ["Air flow logged from simulation."    "Fuel rate logged from simulation."    "Air fuel ratio calculated by dividing air flow by fuel rate."]
                           ChannelUnit: ["g/s"    "g/s"    <missing>]
                           ChannelType: [FixedLength    FixedLength    Missing]
                       ChannelDataType: [RealLittleEndian    RealLittleEndian    Missing]
                        ChannelNumBits: [64 64 NaN]
                  ChannelComponentType: [None    None    Missing]
                ChannelCompositionType: [None    None    Missing]
                     ChannelSourceName: [""    ""    <missing>]
                     ChannelSourcePath: [""    ""    <missing>]
                  ChannelSourceComment: [""    ""    <missing>]
                     ChannelSourceType: [Unspecified    Unspecified    Missing]
                  ChannelSourceBusType: [Unspecified    Unspecified    Missing]
         ChannelSourceBusChannelNumber: [0 0 0]
                     ChannelReadOption: [All    All    Missing]

新しいMDFファイルを作成する

この手順では、元のファイル VehicleData.mf4 と同じファイル メタデータを持つ VehicleDataNew.mf4 という名前の新しい MDF ファイルを作成します。

関数mdfInfo.を使用して、元のMDFファイルVehicleData.mf4のファイルメタデータを含むMDFInfoオブジェクトを取得します。

info = mdfInfo("VehicleData.mf4")
info = 
  MDFInfo with properties:

   File Details
                  Name: "VehicleData.mf4"
                  Path: "/tmp/Bdoc25a_2864802_1974203/tp6f7be44e/vnt-ex28629694/VehicleData.mf4"
                Author: "Engineer"
            Department: "Automotive"
               Project: "Demo"
               Subject: "Prototype"
               Comment: "Example file"
               Version: "4.20"
      InitialTimestamp: 2024-11-14 19:16:35.000000000

   Creator Details
     ProgramIdentifier: "MATLAB"
     CreatorVendorName: "The MathWorks, Inc."
       CreatorToolName: "MATLAB"
    CreatorToolVersion: "25.1.0.2768609 (R2025a) Prerelease"
       CreatorUserName: "engineer"
        CreatorComment: "Created with Vehicle Network Toolbox"

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

オプション引数 FileInfo を取得したばかりの MDFInfo オブジェクトに設定して関数 mdfCreate を呼び出します。これにより、VehicleData.mf4 と同じファイル メタデータを持つ新しいスケルトン MDF ファイル VehicleDataNew.mf4 がディスク上に作成されます。

mdfCreate("VehicleDataNew.mf4", FileInfo=info)
ans = 
"/tmp/Bdoc25a_2864802_1974203/tp6f7be44e/vnt-ex28629694/VehicleDataNew.mf4"

FileInfo はオプションの名前と値のペアです。指定されていない場合、mdfCreate はデフォルトのファイル メタデータを使用して新しいスケルトン MDF ファイルを作成します。

mdfCreate は新しく作成されたファイルにのみ適用可能なメタデータを設定することに注意してください。たとえば、NamePath などのプロパティは各ファイルに固有のものであるため、無視されます。

ファイルのメタデータを調べる

mdfCreate がファイル メタデータを正しく適用して MDF ファイルを作成したことを確認するには、mdfInfo を使用して VehicleDataNew.mf4 のファイル メタデータを調べます。ファイルにはまだチャネル グループがないため、ChannelGroupCount は 0 であることに注意してください。

mdfInfo("VehicleDataNew.mf4")
ans = 
  MDFInfo with properties:

   File Details
                  Name: "VehicleDataNew.mf4"
                  Path: "/tmp/Bdoc25a_2864802_1974203/tp6f7be44e/vnt-ex28629694/VehicleDataNew.mf4"
                Author: "Engineer"
            Department: "Automotive"
               Project: "Demo"
               Subject: "Prototype"
               Comment: "Example file"
               Version: "4.20"
      InitialTimestamp: 2024-11-14 19:16:35.000000000

   Creator Details
     ProgramIdentifier: "MATLAB"
     CreatorVendorName: "The MathWorks, Inc."
       CreatorToolName: "MATLAB"
    CreatorToolVersion: "25.1.0.2847070 (R2025a) Prerelease Update 3"
       CreatorUserName: "engineer"
        CreatorComment: "Created with Vehicle Network Toolbox"

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

新しいMDFファイルの新しいチャネルグループに更新されたデータを書き込む

オプション引数 GroupNumber を指定せずに関数 mdfWrite を呼び出します。このように使用すると、この関数は入力 timetable を新しいチャネル グループとしてターゲット ファイルの末尾に追加します。この時点での VehicleDataNew.mf4 はチャネル グループのないスケルトン ファイルであるため、この操作により chanGrp2TT がチャネル グループ 1 に書き込まれます。

mdfWrite("VehicleDataNew.mf4", chanGrp2TT)

データを検証する

mdfWrite が MDF ファイルを期待どおりに更新したことを確認するには、VehicleDataNew.mf4 のファイル詳細を再度表示します。ChannelGroupCount が現在 1 であることに注意してください。

mdfInfo("VehicleDataNew.mf4")
ans = 
  MDFInfo with properties:

   File Details
                  Name: "VehicleDataNew.mf4"
                  Path: "/tmp/Bdoc25a_2864802_1974203/tp6f7be44e/vnt-ex28629694/VehicleDataNew.mf4"
                Author: "Engineer"
            Department: "Automotive"
               Project: "Demo"
               Subject: "Prototype"
               Comment: "Example file"
               Version: "4.20"
      InitialTimestamp: 2024-11-14 19:16:35.000000000

   Creator Details
     ProgramIdentifier: "MATLAB"
     CreatorVendorName: "The MathWorks, Inc."
       CreatorToolName: "MATLAB"
    CreatorToolVersion: "25.1.0.2847070 (R2025a) Prerelease Update 3"
       CreatorUserName: "engineer"
        CreatorComment: "Created with Vehicle Network Toolbox"

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

メタデータが含まれた新しい MDF ファイルのチャネル グループ 1 からデータを読み取ります。サンプル数が減り、新しいチャネル AirFuelRatio が追加されていることに注目してください。

chanGrp1DataNew = mdfRead("VehicleDataNew.mf4", GroupNumber=1, IncludeMetadata=true)
chanGrp1DataNew = 1×1 cell array
    {18634×3 timetable}

chanGrp1TTNew = chanGrp1DataNew{1}
chanGrp1TTNew=18634×3 timetable
             time         AirFlow    FuelRate    AirFuelRatio
        ______________    _______    ________    ____________

        0 sec             17.294       1.209        14.304   
        0.00056199 sec    17.263       1.209        14.278   
        0.0033719 sec     17.112       1.209        14.154   
        0.01 sec          16.776      1.1729        14.303   
        0.02 sec          16.316      1.1409        14.301   
        0.03 sec          15.907      1.1124          14.3   
        0.04 sec          15.546      1.0873        14.298   
        0.05 sec          15.228      1.0652        14.296   
        0.055328 sec      15.075      1.0652        14.152   
        0.055328 sec      15.075      1.0652        14.152   
        0.055328 sec      15.075      1.0652        14.152   
        0.06 sec          14.949      1.0458        14.294   
        0.064672 sec      14.832      1.0458        14.182   
        0.07 sec          14.707      1.0289        14.293   
        0.08 sec          14.497      1.0143        14.292   
        0.09 sec          14.317      1.0019         14.29   
      ⋮

チャネルグループメタデータとチャネルメタデータを調べる

timetable のカスタム プロパティにアクセスして、チャネル グループ 1 とこのグループ内のチャネルのメタデータを調べます。

chanGrp1TTNew.Properties.CustomProperties
ans = 
CustomProperties with properties:

                              Validity: [18634×3 timetable]
           ChannelGroupAcquisitionName: ""
                   ChannelGroupComment: "Simulation of engine gas dynamics. Update: Removed invalid samples and added new channel "AirFuelRatio"."
                ChannelGroupSourceName: ""
                ChannelGroupSourcePath: ""
             ChannelGroupSourceComment: ""
                ChannelGroupSourceType: Unspecified
             ChannelGroupSourceBusType: Unspecified
    ChannelGroupSourceBusChannelNumber: 0
                    ChannelDisplayName: [""    ""    ""]
                        ChannelComment: ["Air flow logged from simulation."    "Fuel rate logged from simulation."    "Air fuel ratio calculated by dividing air flow by fuel rate."]
                           ChannelUnit: ["g/s"    "g/s"    ""]
                           ChannelType: [FixedLength    FixedLength    FixedLength]
                       ChannelDataType: [RealLittleEndian    RealLittleEndian    RealLittleEndian]
                        ChannelNumBits: [64 64 64]
                  ChannelComponentType: [None    None    None]
                ChannelCompositionType: [None    None    None]
                     ChannelSourceName: [""    ""    ""]
                     ChannelSourcePath: [""    ""    ""]
                  ChannelSourceComment: [""    ""    ""]
                     ChannelSourceType: [Unspecified    Unspecified    Unspecified]
                  ChannelSourceBusType: [Unspecified    Unspecified    Unspecified]
         ChannelSourceBusChannelNumber: [0 0 0]
                     ChannelReadOption: [All    All    All]