MATLAB Answers

MDF (mf4) unsorted

36 views (last 30 days)
Christian Steiniche
Christian Steiniche on 1 Mar 2019
Commented: Ichechi Weli on 13 Apr 2020
Hi all
I am trying to load a MDF (mf4) file into matlab using Vehicle Network Toolbox.
I execute the following to get file information:
m = mdf('C:\log_1.mf4');
The result is:
m =
MDF with properties:
File Details
Name: 'log_1.mf4'
Path: 'C:\log_1.mf4'
Author: ''
Department: ''
Project: ''
Subject: ''
Comment: ''
Version: '4.11'
DataSize: 193468
InitialTimestamp: ''
File Contents
Attachment: [0×0 struct]
ChannelNames: {2×1 cell}
ChannelGroup: [1×2 struct]
ans =
struct with fields:
AcquisitionName: 'CAN'
Comment: ''
NumSamples: 3587
DataSize: 78914
Sorted: 0
Channel: [1×8 struct]
ans =
8×1 cell array
{'ID' }
{'IDE' }
{'DLC' }
{'DataLength' }
{'DataBytes' }
{'Dir' }
{'Timestamp' }
Then I run the following to read the log entris in the file:
read(m, 1, m.ChannelNames{1}, 1, 10)
The result is:
Error using mdfReadTest (line 12)
Functionality is not implemented for the MDF file.
It seems that Matlab is not able to load unsorted MDF files (Sorted: 0). It works if I use a third-party tool to first sort the file.
Can you confirm that it is not possible to load unsorted files in Matlab? And if so, any plans to add this functionality?

Answers (1)

Ichechi Weli
Ichechi Weli on 10 Feb 2020
As of MATLAB 2019b, if you get that error you can use the mdfsort function to sort the file beforehand.
Ichechi Weli
Ichechi Weli on 13 Apr 2020
I'm not sure, I'd have to look into and find a workaound. But below is the built-in mdfsort.m function from R2019b, maybe you can play with it and come up with something that works.
function sortedMDFPath = mdfSort(srcFile, destFile)
% mdfSort Create a sorted copy of an unsorted MDF file.
% SORTEDMDFPATH = mdfSORT(SRCFILE, DESTFILE) takes an unsorted MDF file
% SRCFILE, and creates a sorted copy of that file as DESTFILE. The path
% to the sorted file is returned as SORTEDMDFPATH.
% Example:
% sortedPath = mdfSort('UnsortedMDFFile.mf4', 'SortedMDFFile.mf4');
% Copyright 2019, The MathWorks, Inc.
% Check the argument count.
narginchk(2, 2);
% Convert strings to character vectors.
srcFile = convertStringsToChars(srcFile);
destFile = convertStringsToChars(destFile);
% Call the MDF info function.
% Construct and run an input parser to check the inputs.
p = inputParser;
p.addRequired('srcFile', @(x)validateattributes(x, {'char'}, {'nonempty', 'row'}, 'MDFSORT', 'SRCFILE'));
p.addRequired('destFile', @(x)validateattributes(x, {'char'}, {'nonempty', 'row'}, 'MDFSORT', 'DESTFILE'));
p.parse(srcFile, destFile);
sortedMDFPath = asam.mdf.FileInterface.Sort(srcFile, destFile);
catch ME
% Simplify error reporting and call stack.
Good luck

Sign in to comment.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!