Plot a vector that contain dates in concatenated number format and plot it using dates

Hello all, I am quite a new user,then sorry if the question is too basic. I got a vector [20000101.1 20000101.2 20000101.3.......20000912.15] the first 4 digits correspond to the year, the second 2 to the month, the third 2 to the day and after the dot is the time in hrs (no minutes, no seconds). Now I would like to plot some values corresponding to these dates where the x axis is displaying the date and time say ( Jan 01 2000, 1 AM...etc). Any idea or advice would be higly appreciated. Thank you very much
Wilson

 採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 9 月 15 日
A = [[20000101.1 20000101.2 20000101.3 20000912.15]];
d = datenum(num2str(A'),'yyyymmdd.HH');
out = datestr(d,'mmm dd yyyy, HH PM');
corrected
A = [20000101.01 20000101.03 20000912.15 20000101.2];
k = strjust(num2str(A'),'left');
k(k == ' ')='0';
out = datestr(datenum(k,'yyyymmdd.HH'),'mmm dd yyyy,HHPM')

3 件のコメント

Jan
Jan 2011 年 9 月 15 日
Do you have any reasons for the doubled square brackets?
Your method cannot distinguis 20000101.1 and 20000101.10.
Oleg Komarov
Oleg Komarov 2011 年 9 月 15 日
To ensure that the decimals won't run away on their own :)
Jan
Jan 2011 年 9 月 15 日
I'm curious how Wilson will handle the ambiguos format.

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

その他の回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2011 年 9 月 15 日
a=[20000101.1 20000101.2 20000101.3 20000912.15];
b=num2str(a');
c=datenum(b,'yyyymmdd.HH');
h=axes;
plot(c,1:4);
d=get(h,'xtick');
e=datestr(d,'mmm dd yyyy HH PM');
set(h,'xticklabel',e)
Jan
Jan 2011 年 9 月 15 日

0 投票

There is no difference between 20000101.1 and 20000101.10 ?! So if your data are really double values, I assume the best would be to create the data again from scratch using a unique format.

1 件のコメント

Oleg Komarov
Oleg Komarov 2011 年 9 月 15 日
Well, it is easy!
20000101.1 --> 2000 01 01 01
20000101.10 --> 2000 01 01 10

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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by