Cell2mat not working for unequal length cell data/array
Show older comments
Hello,
I am trying to process and plot the CAN message data in Matlab. To do this I am using the following code to import data from *.asc file into Matlab workspace.
canMsgs = canMessageImport('MsgLog.asc', 'Vector', candb, 'OutputFormat', 'timetable')
(my understanding is this code imports hex data for every row in the log file as cell array (as dec numbers) in the output)
Once the data is been loaded into workspace, I am converting the imported timetable data to table format using the below comand.
canMsgs = timetable2table(canMsgs).
The cell array loaded from CAN data is off different length (depending on the byte size (4,6,8)) and when I use the cell2mat function to split the cell array into individual columns I am getting the following error. I am looping through to do this with the below code
for i = 1:length(canMsgs.Data)
C(i,:) = cell2mat(canMsgs.Data(i));
end
Below is the error I am seeing
Subscripted assignment dimension mismatch.
Error in CAN_Test (line 23)
C(i,:) = cell2mat(canMsgs.Data(i));
I have attached a screenshot from matlab workspace showing the data size, below is the sample data. Individual line represents single cell array (can be seen in the attached image for reference)
[0,0,0,0,0,0,0,0]
[10,0,0,0,0,15,39,0]
[0,0,0,0,230,3,0,0]
[1,0,0,0,0]
[47,255,0,0,70,129,0]
[0,255,0,0,0,1]
[0,0,0,0,0,6,37,0]
[0,0,0,0,48,248,88,27]
[170,0,0,0,0,64,0,0]
Please help me to fix this issue.
Thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!