How to plot strings in an cell array as x axis.

Hello, I'm working on synchronising data from two different sources. Sample data from the two sources are timecoded in this format
HH:MM:SS.FFF
where the FFF is milliseconds.
It doesn't seem that this is some form of supported data format in Matlab(?) so I have the timeseries stored as strings in an cell array. The question is if it is possible to plot the data as a function of this cell array or if there is a smarter way to perform this.
Best regards.

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 10 Dez. 2012

0 Stimmen

This format is supported by Matlab
Example
datestr(now,'HH:MM:SS:FFF')
Jan
Jan am 10 Dez. 2012
Bearbeitet: Jan am 10 Dez. 2012

0 Stimmen

You can convert the time strings manually.
C = {'12:13:14.156', '12:13:16.157'}
n = numel(C);
S = sprintf('%s*', C{:});
N = sscanf(S, '%d:%d:%f*', [3, n]); % Or [n, 3] ?!
N = [zeros(n, 3), transpose(N);
DNum = datenum(N);
Another simpler but slower solution:
C2 = strcat({'10-Dec-2012 '}, C);
DNum = datenum(C2, 'dd-mmm-yyyy HH:MM:SS.FFF');
(I cannot test this currently.)

2 Kommentare

Nikolai
Nikolai am 10 Dez. 2012
Thanks, this worked well. But is it possible to show the original timecode format (HH:MM:SS.FFF) as the x axis value instead of datenum value? This would make synchronization with another source much easier.
Jan
Jan am 10 Dez. 2012
Does the datetick() command help? Or perhaps FEX: ticklabelformat

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Gefragt:

am 10 Dez. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by