How can i read from CAN and save the messages in a timetable?

4 views (last 30 days)
Hi... i'm trying to read messages from CAN and i have (maybe a simple) problem that i don't know how to fix.
The thing is... everything is ok about reading but about saving... well...
Let me explain with some code
start(rxCh); % i start a channel to receive
tic; % start a timmer
while (toc < samplingtime) % i want to reaad the CAN messages for a 'samplingtime'
for t=0:1:samplingtime*samplefreq %so if i want to read every 1s during 10 s (ex) i will read 10 times
rxMsg= receive(rxCh, Inf, 'OutputFormat', 'timetable'); % my problem is right here
pause(timebsamples); % i will wait a litle bit (in the case of the example it will be 1 sec)
toc %just to check the times
end
end
My problem is when i update the rxMsg i loose everything that i had there before.
can someone give me a help... i don't want to loose information ...
Thanks in advance

Accepted Answer

Peter Perkins
Peter Perkins on 19 Dec 2017
Jose, I think typically you would want to vertically concatenate all the timetables you get. You might either do something like
rxMsg = [rxMsg; receive(...)];
or
rxMsg = cell(1,N);
for ...
...
rxMsg{t} = receive(...);
...
end
rxMsg = vertcat(rxMsg{:});
but it's hard to tell what you are really going for.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!