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.

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 10 日

0 投票

This format is supported by Matlab
Example
datestr(now,'HH:MM:SS:FFF')
Jan
Jan 2012 年 12 月 10 日
編集済み: Jan 2012 年 12 月 10 日

0 投票

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 件のコメント

Nikolai
Nikolai 2012 年 12 月 10 日
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 2012 年 12 月 10 日
Does the datetick() command help? Or perhaps FEX: ticklabelformat

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

製品

質問済み:

2012 年 12 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by