Converting a cell array to can message timetable
I am trying to convert a cell array into can message timetable format ,
% Given cell array
canMessageCell = {‘Timestamp 1546909042’, ‘Interface ”can0”’, ‘ID ”0B9”’, ‘Data [0,4,0,0,0,0,0,0]’};
% Extract the information from the cell array
timestampStr = canMessageCell{1};
idStr = canMessageCell{3};
dataStr = canMessageCell{4};
% Convert extracted strings to proper data types
timestamp = datetime(str2double(extractAfter(timestampStr, ‘Timestamp ‘)), ‘ConvertFrom’, ‘posixtime’);
id = hex2dec(extractBetween(idStr, ‘ID ”’, ””));
% Extract the data portion and convert it to a numeric array
dataChar = extractBetween(dataStr, ‘Data [‘, ‘]’);
data = str2num(dataChar{1}); % Convert cell array to character vector before using str2num
% Assume the CAN message is not an extended frame, not a remote frame, and has no error
isExtended = false;
isRemote = false;
hasError = false;
% Create a structure array with the expected field names
canMessageStruct = struct(‘TimeStamp’, timestamp, ‘ID’, id, ‘Data’, {data}, ‘Extended’, isExtended, ‘Remote’, isRemote, ‘Error’, hasError);
% Convert the structure array to a cell array
canMessageCell = {canMessageStruct};
% Load the DBC file (replace with the actual path to your DBC file)
dbcFile = ‘drivekit_kia_soul_ev.dbc’;
db = canDatabase(dbcFile);
% Convert the cell array to a canMessageTimetable
msgTimetable = canMessageTimetable(canMessageCell, db);
% Display the result
disp(msgTimetable);
I am following this syntax for converting my cell array into CAN message timetable db = canDatabase(‘myDatabase.dbc’)
msgTimetable = canMessageTimetable(canMsgs,db) but I am getting this error, Error using ()
Timetable row subscript must be a numeric, logical, or datetime array, or a timerange subscripter.
Error in canmessagetimetableconversion (line 33)
msgTimetable = canMessageTimetable(canMessageCell, db);
I dont know why because my timestamp is in datetime format as i converted it from posix format, my data is in uint8 format and I have created a struct for my timestamp, ID , Data , I have assumed Extended, Remote, Error to be false , if anyone can please help me in debugging this issue as i have been stuck on this , it would be greatly appreciated.I am trying to convert a cell array into can message timetable format ,
% Given cell array
canMessageCell = {‘Timestamp 1546909042’, ‘Interface ”can0”’, ‘ID ”0B9”’, ‘Data [0,4,0,0,0,0,0,0]’};
% Extract the information from the cell array
timestampStr = canMessageCell{1};
idStr = canMessageCell{3};
dataStr = canMessageCell{4};
% Convert extracted strings to proper data types
timestamp = datetime(str2double(extractAfter(timestampStr, ‘Timestamp ‘)), ‘ConvertFrom’, ‘posixtime’);
id = hex2dec(extractBetween(idStr, ‘ID ”’, ””));
% Extract the data portion and convert it to a numeric array
dataChar = extractBetween(dataStr, ‘Data [‘, ‘]’);
data = str2num(dataChar{1}); % Convert cell array to character vector before using str2num
% Assume the CAN message is not an extended frame, not a remote frame, and has no error
isExtended = false;
isRemote = false;
hasError = false;
% Create a structure array with the expected field names
canMessageStruct = struct(‘TimeStamp’, timestamp, ‘ID’, id, ‘Data’, {data}, ‘Extended’, isExtended, ‘Remote’, isRemote, ‘Error’, hasError);
% Convert the structure array to a cell array
canMessageCell = {canMessageStruct};
% Load the DBC file (replace with the actual path to your DBC file)
dbcFile = ‘drivekit_kia_soul_ev.dbc’;
db = canDatabase(dbcFile);
% Convert the cell array to a canMessageTimetable
msgTimetable = canMessageTimetable(canMessageCell, db);
% Display the result
disp(msgTimetable);
I am following this syntax for converting my cell array into CAN message timetable db = canDatabase(‘myDatabase.dbc’)
msgTimetable = canMessageTimetable(canMsgs,db) but I am getting this error, Error using ()
Timetable row subscript must be a numeric, logical, or datetime array, or a timerange subscripter.
Error in canmessagetimetableconversion (line 33)
msgTimetable = canMessageTimetable(canMessageCell, db);
I dont know why because my timestamp is in datetime format as i converted it from posix format, my data is in uint8 format and I have created a struct for my timestamp, ID , Data , I have assumed Extended, Remote, Error to be false , if anyone can please help me in debugging this issue as i have been stuck on this , it would be greatly appreciated. I am trying to convert a cell array into can message timetable format ,
% Given cell array
canMessageCell = {‘Timestamp 1546909042’, ‘Interface ”can0”’, ‘ID ”0B9”’, ‘Data [0,4,0,0,0,0,0,0]’};
% Extract the information from the cell array
timestampStr = canMessageCell{1};
idStr = canMessageCell{3};
dataStr = canMessageCell{4};
% Convert extracted strings to proper data types
timestamp = datetime(str2double(extractAfter(timestampStr, ‘Timestamp ‘)), ‘ConvertFrom’, ‘posixtime’);
id = hex2dec(extractBetween(idStr, ‘ID ”’, ””));
% Extract the data portion and convert it to a numeric array
dataChar = extractBetween(dataStr, ‘Data [‘, ‘]’);
data = str2num(dataChar{1}); % Convert cell array to character vector before using str2num
% Assume the CAN message is not an extended frame, not a remote frame, and has no error
isExtended = false;
isRemote = false;
hasError = false;
% Create a structure array with the expected field names
canMessageStruct = struct(‘TimeStamp’, timestamp, ‘ID’, id, ‘Data’, {data}, ‘Extended’, isExtended, ‘Remote’, isRemote, ‘Error’, hasError);
% Convert the structure array to a cell array
canMessageCell = {canMessageStruct};
% Load the DBC file (replace with the actual path to your DBC file)
dbcFile = ‘drivekit_kia_soul_ev.dbc’;
db = canDatabase(dbcFile);
% Convert the cell array to a canMessageTimetable
msgTimetable = canMessageTimetable(canMessageCell, db);
% Display the result
disp(msgTimetable);
I am following this syntax for converting my cell array into CAN message timetable db = canDatabase(‘myDatabase.dbc’)
msgTimetable = canMessageTimetable(canMsgs,db) but I am getting this error, Error using ()
Timetable row subscript must be a numeric, logical, or datetime array, or a timerange subscripter.
Error in canmessagetimetableconversion (line 33)
msgTimetable = canMessageTimetable(canMessageCell, db);
I dont know why because my timestamp is in datetime format as i converted it from posix format, my data is in uint8 format and I have created a struct for my timestamp, ID , Data , I have assumed Extended, Remote, Error to be false , if anyone can please help me in debugging this issue as i have been stuck on this , it would be greatly appreciated. cell array, can message timetable conversion MATLAB Answers — New Questions