Read MDF Channels with Partial Conversion
R2026bThis example shows you how to read physical values from MDF channels that contain partial conversion rules using the mdfRead function.
Introduction to Partial Conversion
According to the ASAM MDF standard, a conversion rule converts raw values to physical values. Most channels have a single conversion rule that applies uniformly to all raw values. However, some channels use partial conversion, where a parent conversion block (CC_Type 7: Value to Text or CC_Type 8: Value Range to Text) maps different ranges of raw values to different child conversion blocks.
In a partial conversion channel, each raw value may be converted by a different child conversion depending on which range it falls into. The child conversions can result in either:
Numeric physical values (e.g., Linear, Rational, Algebraic, or Identity conversions)
String physical values (e.g., Value Range to Text)
When an MDF channel uses partial conversion rules, certain raw values convert to doubles and others to strings. When reading such a channel with ReadRaw=false:
For raw numerical values that convert to numerical values,
mdfReadnow returns physical values as doubles.For raw numerical values that convert to strings, the function returns the unconverted numerical raw value as a double and issues a warning.
Read a Partial Conversion Channel with Only Numeric Conversions
The file PartialConversionExample.mf4 contains a "Numeric" channel with a parent RTABX (CC_Type 8) conversion block that maps raw values to the following child conversions:
For 0.5 <= Raw < 2.5: Linear conversion,
For 2.5 <= Raw < 3.5: Identity conversion,
For 3.5 <= Raw < 6.0: Algebraic conversion,
Default: Linear conversion,
Read the channel data with ReadRaw=false (default) to get physical values. Since all child conversions produce numeric values, mdfRead with ReadRaw=false returns fully converted physical values.
fileName = "PartialConversionExample.mf4"; dataPhys_Numeric = mdfRead(fileName, Channel="Numeric"); dataPhys_Numeric{1}
ans = 10×1 timetable
t Numeric
_______ _______
0 sec 8.01
0.1 sec 10.35
0.2 sec 11.286
0.3 sec 2.8
0.4 sec 3
0.5 sec -12
0.6 sec -20
0.7 sec -1
0.8 sec -1
0.9 sec -1
Get insights using Copilot
Read the same channel with ReadRaw=true to get raw values for comparison.
dataRaw_Numeric = mdfRead(fileName, Channel="Numeric", ReadRaw=true);
dataRaw_Numeric{1}ans = 10×1 timetable
t Numeric
_______ _______
0 sec 1
0.1 sec 2
0.2 sec 2.4
0.3 sec 2.8
0.4 sec 3
0.5 sec 4
0.6 sec 5
0.7 sec 0
0.8 sec 7
0.9 sec 10
Get insights using Copilot
Compare the physical values, raw values, and the calculated physical values based on the conversion rules side by side.
The helper function calcPartialConversion is provided solely to facilitate understanding of the conversion behavior. It applies the known conversion rules for each channel and returns a comparison table showing the raw value, the physical value from mdfRead, the independently calculated value, and the name of the conversion rule applied. The conversion rule details are determined from external tools such as the Vector MDF Validator tool, and hardcoded in the helper function.
comparison = calcPartialConversion(dataRaw_Numeric{1}.Numeric, dataPhys_Numeric{1}.Numeric, "Numeric")comparison = 10×4 table
Raw Physical Calculated ConversionRuleApplied
___ ________ __________ _____________________
1 8.01 8.01 "Linear"
2 10.35 10.35 "Linear"
2.4 11.286 11.286 "Linear"
2.8 2.8 2.8 "Identity"
3 3 3 "Identity"
4 -12 -12 "Algebraic"
5 -20 -20 "Algebraic"
0 -1 -1 "Linear (default)"
7 -1 -1 "Linear (default)"
10 -1 -1 "Linear (default)"
Get insights using Copilot
Read a Partial Conversion Channel with Mixed Numeric and String Conversions
The same file contains a "Mixed" channel with a parent RTABX conversion block that maps raw values to:
Raw values 0 to 10: Value Range to Text conversion that produces string values
For 0 <= Raw < 2: "very low"
For 2 <= Raw < 4: "low"
For 4 <= Raw < 6: "medium"
For 6 <= Raw < 8: "high"
For 8 <= Raw < 10: "very high"
For 10 <= Raw < 20: Rational conversion,
Default: Linear conversion,
When mdfRead reads this channel with ReadRaw=false, it applies numeric conversions where possible and returns the raw value as a double for ranges that map to string values. A warning is also thrown.
Read the physical values of this channel. A warning is expected because the channel contains a mix of numeric and string conversions.
dataPhys_Mixed = mdfRead(fileName, Channel="Mixed");Warning: mdfRead returned a mix of physical and raw values in channel group 1 for partial conversion channels: "Mixed".
dataPhys_Mixed{1}ans = 10×1 timetable
t Mixed
_______ _______
0 sec 1
0.1 sec 3
0.2 sec 5
0.3 sec 7
0.4 sec 9
0.5 sec 0.5664
0.6 sec 0.57263
0.7 sec 0.57691
0.8 sec 24
0.9 sec -6
Get insights using Copilot
Read the same channel with ReadRaw=true to get raw values for comparison.
dataRaw_Mixed = mdfRead(fileName, Channel="Mixed", ReadRaw=true);
dataRaw_Mixed{1}ans = 10×1 timetable
t Mixed
_______ _____
0 sec 1
0.1 sec 3
0.2 sec 5
0.3 sec 7
0.4 sec 9
0.5 sec 12
0.6 sec 15
0.7 sec 18
0.8 sec 25
0.9 sec -5
Get insights using Copilot
Compare the physical values, raw values, and the calculated physical values based on the conversion rules side by side.
For raw values in the 0-10 range (which map to string values), notice the raw value itself is returned since the string cannot be stored in a numeric array.
comparison = calcPartialConversion(dataRaw_Mixed{1}.Mixed, dataPhys_Mixed{1}.Mixed, "Mixed")comparison = 10×4 table
Raw Physical Calculated ConversionRuleApplied
___ ________ __________ ____________________________________
1 1 1 "Value range to text (raw returned)"
3 3 3 "Value range to text (raw returned)"
5 5 5 "Value range to text (raw returned)"
7 7 7 "Value range to text (raw returned)"
9 9 9 "Value range to text (raw returned)"
12 0.5664 0.5664 "Rational"
15 0.57263 0.57263 "Rational"
18 0.57691 0.57691 "Rational"
25 24 24 "Linear (default)"
-5 -6 -6 "Linear (default)"
Get insights using Copilot
Read a Status String Table Channel
Status string table channels are internally modeled as partial conversion channels within MDF files. For raw values that map to strings, the value converted by the default conversion rule is returned.
The same file contains a "StatusString" channel with a status string table:
For 0 <= Raw < 20: String "Error A"
For 20 <= Raw < 30: String "Error B"
Default: Algebraic conversion,
Read the physical values of this status string table channel.
dataPhys_StatusString = mdfRead(fileName, Channel = "StatusString");
dataPhys_StatusString{1}ans = 10×1 timetable
t StatusString
_______ ____________
0 sec 0.1
0.1 sec 0.066667
0.2 sec 0.05
0.3 sec 0.041667
0.4 sec 0.037037
0.5 sec 0.033333
0.6 sec 0.029412
0.7 sec 0.025
0.8 sec 0.018182
0.9 sec 0.5
Get insights using Copilot
Read the same channel with ReadRaw=true to get raw values for comparison.
dataRaw_StatusString = mdfRead(fileName, Channel = "StatusString", ReadRaw=true);
dataRaw_StatusString{1}ans = 10×1 timetable
t StatusString
_______ ____________
0 sec 5
0.1 sec 10
0.2 sec 15
0.3 sec 19
0.4 sec 22
0.5 sec 25
0.6 sec 29
0.7 sec 35
0.8 sec 50
0.9 sec -3
Get insights using Copilot
Compare the physical values, raw values, and the calculated physical values based on the conversion rules side by side.
For status string table channels, notice all values are converted by the default algebraic conversion, regardless of whether the raw value maps to a string.
comparison = calcPartialConversion(dataRaw_StatusString{1}.StatusString, dataPhys_StatusString{1}.StatusString, "StatusString")comparison = 10×4 table
Raw Physical Calculated ConversionRuleApplied
___ ________ __________ __________________________________________________
5 0.1 0.1 "Value range to text (default conversion applied)"
10 0.066667 0.066667 "Value range to text (default conversion applied)"
15 0.05 0.05 "Value range to text (default conversion applied)"
19 0.041667 0.041667 "Value range to text (default conversion applied)"
22 0.037037 0.037037 "Value range to text (default conversion applied)"
25 0.033333 0.033333 "Value range to text (default conversion applied)"
29 0.029412 0.029412 "Value range to text (default conversion applied)"
35 0.025 0.025 "Linear (default)"
50 0.018182 0.018182 "Linear (default)"
-3 0.5 0.5 "Linear (default)"
Get insights using Copilot