このページは機械翻訳を使用して翻訳されました。最新版の英語を参照するには、ここをクリックします。
MDF ファイル内のチャネル グループ データを上書きする
この例では、MDF ファイルのチャネル グループに記録されたデータを処理し、更新されたデータを同じチャネル グループに書き戻す方法を示します。この例で使用されている MDF ファイル VehicleData.mf4 には、2 つのチャネル グループの 2 つのシミュレーションから記録されたデータが含まれていますが、この例はチャネル グループ 1 のデータでのみ機能します。
まず、チャネル グループ 1 から timetable にデータを読み込み、次にデータのコピーに対して修正と削減を実行し、最後に更新されたデータで同じチャネル グループを上書きします。
ファイルとチャネルグループの詳細を表示する
ファイル名を指定して mdfInfo を使用して MDF ファイルのメタデータを表示します。
mdfInfo("VehicleData.mf4")ans =
MDFInfo with properties:
File Details
Name: "VehicleData.mf4"
Path: "/tmp/Bdoc25a_2864802_1974203/tp6f7be44e/vnt-ex75859393/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
メタデータを含むチャネル グループ データの読み取り
オプション引数 IncludeMetadata を true に設定した mdfRead 関数を使用して、チャネル グループ 1 からデータを読み取ります。出力 timetable chanGrp1TT は、チャネル グループ 1 内のすべてのチャネルのデータのコピーです。
chanGrp1Data = mdfRead("VehicleData.mf4", GroupNumber=1, IncludeMetadata=true)chanGrp1Data = 1×1 cell array
{751×8 timetable}
chanGrp1TT = chanGrp1Data{1}chanGrp1TT=751×8 timetable
time EngineRPM Brake Throttle Gear ImpellerTorque OutputTorque TransmissionRPM VehicleSpeed
________ _________ _____ ________ ____ ______________ ____________ _______________ ____________
0 sec 1000 0 60 1 52.919 282.65 0 0
0.04 sec 1383.3 0 59.946 1 101.4 532.63 13.593 0
0.08 sec 1685.4 0 59.893 1 150.76 776.41 35.847 0
0.12 sec 1907.2 0 59.839 1 193.42 973.15 65.768 0
0.16 sec 2062 0 59.785 1 227.02 1117.6 101.53 0
0.2 sec 2161.2 0 59.732 1 251.11 1212.8 141.45 0
0.24 sec 2221.4 0 59.678 1 267.24 1264.3 183.86 0
0.28 sec 2257.2 0 59.624 1 276.35 1271.2 227.25 0
0.32 sec 2278.7 0 59.57 1 281.99 1259.5 270.52 0
0.36 sec 2292.4 0 59.517 1 283.39 1229 313.08 0
0.4 sec 2305.1 0 59.463 1 283.29 1193.4 354.43 0
0.44 sec 2317.4 0 59.409 1 282.91 1156.6 394.58 0
0.48 sec 2330.5 0 59.356 1 281.84 1112.8 433.27 0
0.52 sec 2344.5 0 59.302 1 281.19 1073.1 470.53 0
0.56 sec 2359.1 0 59.248 1 279.77 1032.9 506.43 0
0.6 sec 2376.4 0 59.195 1 277.89 993.97 540.92 0
⋮
mdfRead 関数呼び出し中に IncludeMetadata が true に設定されているため、出力 timetable にはチャネル グループ 1 とこのグループ内のすべてのチャネルのメタデータも含まれます。チャネル グループのメタデータは、テーブル全体の timetable のカスタム プロパティとして保存され、プロパティ名には「ChannelGroup」というプレフィックスが付きます。個々のチャネルのメタデータは、変数の timetable のカスタム プロパティとして保存され、プロパティ名には「Channel」というプレフィックスが付きます。
チャネル グループ 1 およびこのグループ内のすべてのチャネルのメタデータを表示します。
chanGrp1TT.Properties.CustomProperties
ans =
CustomProperties with properties:
Validity: [751×8 timetable]
ChannelGroupAcquisitionName: ""
ChannelGroupComment: "Simulation of an automatic transmission controller during passing maneuver."
ChannelGroupSourceName: ""
ChannelGroupSourcePath: ""
ChannelGroupSourceComment: ""
ChannelGroupSourceType: Unspecified
ChannelGroupSourceBusType: Unspecified
ChannelGroupSourceBusChannelNumber: 0
ChannelDisplayName: ["" "" "" "" "" "" "" ""]
ChannelComment: ["" "" "" "" "" "" "" ""]
ChannelUnit: ["rpm" "ft*lbf" "%" "" "ft*lbf" "ft*lbf" "rpm" "mph"]
ChannelType: [FixedLength FixedLength FixedLength FixedLength FixedLength FixedLength FixedLength FixedLength]
ChannelDataType: [RealLittleEndian IntegerUnsignedLittleEndian RealLittleEndian IntegerUnsignedLittleEndian RealLittleEndian RealLittleEndian RealLittleEndian RealLittleEndian]
ChannelNumBits: [64 8 64 8 64 64 64 64]
ChannelComponentType: [None None None None None None None None]
ChannelCompositionType: [None None None None None None None None]
ChannelSourceName: ["" "" "" "" "" "" "" ""]
ChannelSourcePath: ["" "" "" "" "" "" "" ""]
ChannelSourceComment: ["" "" "" "" "" "" "" ""]
ChannelSourceType: [Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified]
ChannelSourceBusType: [Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified Unspecified]
ChannelSourceBusChannelNumber: [0 0 0 0 0 0 0 0]
ChannelReadOption: [All All All All All All All All]
mdfRead 関数を呼び出す場合、IncludeMetadata はデフォルトで false に設定されることに注意してください。チャネル グループ データの読み取りの最終目的が、データが読み取られる同じチャネル グループを上書きすることである場合は、IncludeMetadata を true に設定する必要があります。
データコピーで選択したサンプルを修正する
この特定のアプリケーションではギアが 4 つしかないため、Gear の有効な値は [1,4] の範囲の整数である必要があります。ただし、ギアシフトが発生するたびに、障害が発生する可能性があるため、Gear の値がゼロにリセットされているようです。
stackedplot を使用して積み重ねプロットを作成し、Gear での急激なゼロ低下が ImpellerTorque および OutputTorque での急激な値の変化と一致することを確認します。
stackedplot(chanGrp1TT, ["ImpellerTorque", "OutputTorque", "Gear"])

Gear の値がゼロになる行インデックスを検索します。
zeroIdx = find(chanGrp1TT.Gear == 0)
zeroIdx = 0×1 empty double column vector
見つかったインデックスのサンプルを修正して、ゼロの直後の値を取得します。
chanGrp1TT.Gear(zeroIdx) = chanGrp1TT.Gear(zeroIdx + 1)
chanGrp1TT=751×8 timetable
time EngineRPM Brake Throttle Gear ImpellerTorque OutputTorque TransmissionRPM VehicleSpeed
________ _________ _____ ________ ____ ______________ ____________ _______________ ____________
0 sec 1000 0 60 1 52.919 282.65 0 0
0.04 sec 1383.3 0 59.946 1 101.4 532.63 13.593 0
0.08 sec 1685.4 0 59.893 1 150.76 776.41 35.847 0
0.12 sec 1907.2 0 59.839 1 193.42 973.15 65.768 0
0.16 sec 2062 0 59.785 1 227.02 1117.6 101.53 0
0.2 sec 2161.2 0 59.732 1 251.11 1212.8 141.45 0
0.24 sec 2221.4 0 59.678 1 267.24 1264.3 183.86 0
0.28 sec 2257.2 0 59.624 1 276.35 1271.2 227.25 0
0.32 sec 2278.7 0 59.57 1 281.99 1259.5 270.52 0
0.36 sec 2292.4 0 59.517 1 283.39 1229 313.08 0
0.4 sec 2305.1 0 59.463 1 283.29 1193.4 354.43 0
0.44 sec 2317.4 0 59.409 1 282.91 1156.6 394.58 0
0.48 sec 2330.5 0 59.356 1 281.84 1112.8 433.27 0
0.52 sec 2344.5 0 59.302 1 281.19 1073.1 470.53 0
0.56 sec 2359.1 0 59.248 1 279.77 1032.9 506.43 0
0.6 sec 2376.4 0 59.195 1 277.89 993.97 540.92 0
⋮
データコピーからチャネルを削除する
この特定のアプリケーションでは、Brake と VehicleSpeed は解析には不要になったと想定します。removevars を使用して、これらの 2 つの変数を timetable から削除します。
chanGrp1TT = removevars(chanGrp1TT, ["Brake", "VehicleSpeed"])
chanGrp1TT=751×6 timetable
time EngineRPM Throttle Gear ImpellerTorque OutputTorque TransmissionRPM
________ _________ ________ ____ ______________ ____________ _______________
0 sec 1000 60 1 52.919 282.65 0
0.04 sec 1383.3 59.946 1 101.4 532.63 13.593
0.08 sec 1685.4 59.893 1 150.76 776.41 35.847
0.12 sec 1907.2 59.839 1 193.42 973.15 65.768
0.16 sec 2062 59.785 1 227.02 1117.6 101.53
0.2 sec 2161.2 59.732 1 251.11 1212.8 141.45
0.24 sec 2221.4 59.678 1 267.24 1264.3 183.86
0.28 sec 2257.2 59.624 1 276.35 1271.2 227.25
0.32 sec 2278.7 59.57 1 281.99 1259.5 270.52
0.36 sec 2292.4 59.517 1 283.39 1229 313.08
0.4 sec 2305.1 59.463 1 283.29 1193.4 354.43
0.44 sec 2317.4 59.409 1 282.91 1156.6 394.58
0.48 sec 2330.5 59.356 1 281.84 1112.8 433.27
0.52 sec 2344.5 59.302 1 281.19 1073.1 470.53
0.56 sec 2359.1 59.248 1 279.77 1032.9 506.43
0.6 sec 2376.4 59.195 1 277.89 993.97 540.92
⋮
更新されたデータを同じチャネルグループに書き戻す
更新されたデータを VehicleData.mf4 のチャネル グループ 1 に書き込みますが、そのためには MDF ファイルを変更する権限が必要です。MDF ファイルへの書き込みアクセス権があるかどうかを確認します。そうでない場合は、MDF ファイルを書き込み可能にします。
[~, values] = fileattrib("VehicleData.mf4"); if ~values.UserWrite fileattrib("VehicleData.mf4", "+w") end
オプション引数 GroupNumber を 1 に設定して関数 mdfWrite を呼び出し、チャネル グループ 1 を chanGrp1TT の更新されたデータで上書きします。
mdfWrite("VehicleData.mf4", chanGrp1TT, GroupNumber=1)Warning: Channel "Brake" removed while overwriting an existing channel group. Data of the corresponding channel will be erased but the channel will still exist.
Warning: Channel "VehicleSpeed" removed while overwriting an existing channel group. Data of the corresponding channel will be erased but the channel will still exist.
前のステップで、2 つの変数 Brake と VehicleSpeed が timetable chanGrp1TT から削除されました。ただし、MDF はバイナリ ファイル形式であるため、チャネル グループ構造を変更するとファイルが破損する可能性があります。したがって、既存のチャネル グループからチャネルを完全に削除することはできません。削除されたチャネルのデータは消去されますが、チャネルはチャネル グループ内に引き続き存在します。
データを検証する
データがファイルに正常に書き込まれたことを確認するには、mdfRead を使用してメタデータなしでチャネル グループ 1 からデータのみを読み取ります。変数 Gear の更新された値を調べます。また、削除された変数 Brake および VehicleSpeed の値は消去され、ゼロにリセットされていることにも注意してください。
chanGrp1DataNew = mdfRead("VehicleData.mf4", GroupNumber=1)chanGrp1DataNew = 1×1 cell array
{751×8 timetable}
chanGrp1TTNew = chanGrp1DataNew{1}chanGrp1TTNew=751×8 timetable
time EngineRPM Brake Throttle Gear ImpellerTorque OutputTorque TransmissionRPM VehicleSpeed
________ _________ _____ ________ ____ ______________ ____________ _______________ ____________
0 sec 1000 0 60 1 52.919 282.65 0 0
0.04 sec 1383.3 0 59.946 1 101.4 532.63 13.593 0
0.08 sec 1685.4 0 59.893 1 150.76 776.41 35.847 0
0.12 sec 1907.2 0 59.839 1 193.42 973.15 65.768 0
0.16 sec 2062 0 59.785 1 227.02 1117.6 101.53 0
0.2 sec 2161.2 0 59.732 1 251.11 1212.8 141.45 0
0.24 sec 2221.4 0 59.678 1 267.24 1264.3 183.86 0
0.28 sec 2257.2 0 59.624 1 276.35 1271.2 227.25 0
0.32 sec 2278.7 0 59.57 1 281.99 1259.5 270.52 0
0.36 sec 2292.4 0 59.517 1 283.39 1229 313.08 0
0.4 sec 2305.1 0 59.463 1 283.29 1193.4 354.43 0
0.44 sec 2317.4 0 59.409 1 282.91 1156.6 394.58 0
0.48 sec 2330.5 0 59.356 1 281.84 1112.8 433.27 0
0.52 sec 2344.5 0 59.302 1 281.19 1073.1 470.53 0
0.56 sec 2359.1 0 59.248 1 279.77 1032.9 506.43 0
0.6 sec 2376.4 0 59.195 1 277.89 993.97 540.92 0
⋮