matlab/matlab-import-export-vehicle-data
Use when importing or exporting vehicle data from/to log files (MDF/MF4/DAT, BLF, ASC/TXT), decoding CAN/CAN FD/LIN messages to signals via DBC, ARXML, or LDF databases, writing timetable data to MDF or BLF files, or calling blfread, blfinfo, blfwrite, mdfRead, mdfWrite, mdfCreate, mdfInfo, canSignalImport, canMessageImport, canMessageTimetable, canFDMessageTimetable, canSignalTimetable, or linMessageTimetable.
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-import-export-vehicle-data
Import, decode, and export vehicle network log files in MATLAB using Vehicle Network Toolbox (VNT).
.mf4/.mdf/.dat, .blf, .asc, or .txt vehicle bus log filesmdfWriteblfwriteblfwrite -- use MDF instead)canMessageExport exists -- use BLF or MDF instead)Before running any operations, determine the MATLAB version:
r = matlabRelease;
tok = regexp(r.Release, 'R(\d{4})([ab])', 'tokens');
matlabYear = str2double(tok{1}{1});
matlabLetter = tok{1}{2};
Before calling BLF/ASC/TXT import or CAN/CAN FD/LIN decode functions, call detect_matlab_toolboxes to confirm Vehicle Network Toolbox is installed. If unavailable, tell the user. Once confirmed in a session, do not re-check.
MDF functions (mdfRead, mdfChannelGroupInfo, mdfInfo, mdfChannelInfo) are base MATLAB (R2023a+) and do not require VNT. Do not use the deprecated mdf() object constructor -- always use the functional API. For reading all groups blindly, mdfRead alone is acceptable. To selectively read or inspect structure first, use mdfChannelGroupInfo or mdfInfo.
For R2026a and earlier, multiplexing is not natively supported in Vehicle Network Toolbox. Apply the demultiplexing modifications described below to decoded signals.
| Source Format | CAN | CAN FD | LIN | Raw (no decode) |
|---------------|-----|--------|-----|-----------------|
| ASC | canSignalImport(f,"Vector",db) | same | -- | canMessageImport(f,"Vector",OutputFormat="timetable") |
| TXT | canSignalImport(f,"Kvaser",db) | same | -- | canMessageImport(f,"Kvaser",OutputFormat="timetable") |
| BLF | blfread(f,Database=db) -> canSignalTimetable | blfread(f,Database=db) -> canFDMessageTimetable -> canSignalTimetable | blfread(f,Database=linDb,ProtocolMode="LIN") -> linMessageTimetable | blfread(f) |
| MDF/MF4/DAT | mdfRead -> canMessageTimetable(tt,db) -> canSignalTimetable | mdfRead -> canFDMessageTimetable(tt,db) -> canSignalTimetable | mdfRead -> linMessageTimetable(tt,linDb) | mdfRead -> timetable directly |
db = canDatabase("path/to/file.dbc"); % CAN and CAN FD
db = arxmlDatabase("path/to/file.arxml"); % CAN only (not CAN FD)
linDb = linDatabase("path/to/file.ldf"); % LIN (R2025a+)
Load once, pass to all decode calls. Multiple databases: canMessageTimetable(tt, [db1, db2]).
In case of DBC files only, determine whether the file contains definitions of multiplexed signals that use extended or hierarchical multiplexing.
For MATLAB R2026a or earlier, it is not possible to determine the multiplexing scheme from the canDatabase object directly. Therefore, inspect the raw DBC text to classify the multiplexing scheme, by
reading the DBC file as text using fileread():
dbcText = fileread("path/to/file.dbc");
Check for extended multiplexing indicators. See references/dbc-multiplexing-syntax.md for the full syntax guide — consult it when parsing unfamiliar DBC signal markers or SG_MUL_VAL_ entries.
hasSgMulValEntries = ~isempty(regexp(dbcText, '^SG_MUL_VAL_\s+\d+', 'once', 'lineanchors'));
hasNestedMuxor = ~isempty(regexp(dbcText, 'SG_\s+\w+\s+m\d+M\s', 'once'));
hasExtendedMux = hasSgMulValEntries || hasNestedMuxor;
Note: SG_MUL_VAL_ may appear in the NS_ (namespace) section as a keyword declaration — this does NOT indicate extended multiplexing. Only match actual data entries that start at the beginning of a line followed by a numeric message ID.
If hasExtendedMux is true, identify which specific messages are affected by parsing the message IDs from SG_MUL_VAL_ entries:
sgMulValMsgIds = regexp(dbcText, '^SG_MUL_VAL_\s+(\d+)', 'tokens', 'lineanchors');
extendedMuxMsgIds = unique(cellfun(@(x) str2double(x{1}), sgMulValMsgIds));
For R2026a and earlier, filter out messages with extended multiplexing (identified in extendedMuxMsgIds) and inform the user.
canSignalImport, blfread, mdfRead, canMessageImport) return different types based on channel count and parameters. Always guard with iscell()/istimetable()/isstruct(). When checking multi-channel results, use iscell() as the primary guard to branch between cell array (multi-channel) vs direct timetable (single channel), then iterate or extract with {n} or {i}.arxmlDatabase does not support CAN FD in MATLAB. It cannot be used with canFDMessageTimetable. When the user provides an ARXML file for CAN FD data, always explain that ARXML does not support CAN FD and they must use canDatabase with a DBC file instead. Do not silently switch to DBC without explaining why.arxmlDatabase exclusively. Do not also load canDatabase as a fallback -- the ARXML database object works identically in canMessageTimetable and canSignalTimetable. Only use canDatabase when the user provides a DBC file.canFDSignalTimetable: This function does not exist. Use canSignalTimetable for both CAN and CAN FD signals.ProtocolMode="LIN": Without it, blfread returns only CAN data.linMessageTimetable exists. Access signal values from timetable columns directly.CAN_DataFrame / LIN_Frame (ASAM standard). NEVER use SourceBusType or AcquisitionSourceType metadata -- not even as a fallback. These fields are vendor-specific and unreliable.canMessageImport default format: Returns legacy can.Message array. Always pass OutputFormat="timetable".blfread, mdfRead, and canMessageImport return cell arrays. Extract with {n} before processing.canSignalImport for ASC/TXT signals: It decodes in one call. Only use canMessageImport when raw message timetables are needed.canSignalImport/canMessageImport with Vector and Kvaser vendors, polymorphic return type handling for multi-channel filesblfinfo for file inspection, blfread with and without ChannelID, CAN vs LIN protocol selectionmdfRead/mdfChannelGroupInfo/mdfChannelInfo, detecting raw CAN/LIN groups by channel name, reading specific groupscanMessageTimetable and canSignalTimetable pipelines, DBC and ARXML database usagecanFDMessageTimetable pipeline, why ARXML does not work for CAN FDlinMessageTimetable usage, accessing signal values from timetable columns (no signal-level function exists)canDatabase vs arxmlDatabase vs linDatabase, which decode functions accept which database typecanDatabase, canMessageTimetable, canFDMessageTimetable, canSignalTimetable pipelines and signal demultiplexingWriting MATLAB timetable data to MDF/MF4 files with mdfWrite.
| Task | Function | Notes |
|------|----------|-------|
| Write timetable to new file | mdfWrite(file, tt) | Appends channel group; file created with warning if missing |
| Overwrite existing group | mdfWrite(file, tt, GroupNumber=N) | Must read with IncludeMetadata=true first |
| Set file metadata | mdfCreate(file, FileInfo=minfo) then mdfWrite() | Supported: Author, Department, Project, Subject, Comment |
| Convert unsupported types | See references/mdf-writing.md | logical -> uint8(), categorical -> double() (stores category index), cell -> string(), datetime col -> posixtime() |
| Write raw CAN frames | Use CAN_DataFrame.ID/DLC/DataLength/DataBytes column naming (ASAM standard) | All 4 columns mandatory (ID, DLC, DataLength, DataBytes). Omitting any one breaks canMessageTimetable re-import. |
| Write raw LIN frames | Use LIN_Frame.ID/ReceivedDataByteCount/DataLength/DataBytes column naming | ASAM standard LIN frame naming |
| Handle datetime RowTimes | Set .TimeZone = 'UTC' or convert to duration | Duration recommended for reliable roundtrips |
Writing CAN and CAN FD message data to BLF files with blfwrite.
| Task | Function | Notes |
|------|----------|-------|
| Write CAN messages | blfwrite(file, tt, chanID, 'CAN') | Use canMessageTimetable to format tt; do not manually build columns |
| Write CAN FD messages | blfwrite(file, tt, chanID, 'CAN FD') | Use canFDMessageTimetable to format tt; up to 64-byte payloads. See references/blf-writing.md for the 13 required columns when building from scratch. |
| CAN/CAN FD mixed | Both supported in one BLF file | Use explicit protocol string per call |
LIN is not supported by VNT's blfwrite. Use MDF for LIN logging. When the user asks to write LIN data to BLF, state this limitation immediately -- do not attempt workarounds or partial solutions before explaining the constraint.
ASC/TXT writing is not supported. There is no canMessageExport counterpart to canMessageImport. Use BLF or MDF for export.
mdfWrite/mdfCreate, type conversion, ASAM CAN/LIN naming, overwriting groups, metadata preservationblfwrite with CAN/CAN FD, canMessageTimetable/canFDMessageTimetable formatting, channel callbacks----
Copyright 2026 The MathWorks, Inc.
Take matlab/matlab-import-export-vehicle-data from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.