help with plotting date/time with data
2 次查看(过去 30 天)
显示 更早的评论
I'm reading some data from an excel file. The file has some heading text, so I'm loading this as,
[C,txt] = xlsread(filename);
C has 31 columns
col-1 = date,
col-2 = month,
col-3 = year,
col-4 = hour,
col-5 = min,
col-6 = sec
col-7 = mydata.
I would like to combine column 1 - 6 and write it as single 'time' as dd/mm/yyyy HH:MM:SS and plot it against 'mydata'.
My script goes, (two first lines of text removed from C)
time = [C(3:end,3) C(3:end,1) C(3:end,2) C(3:end,4) C(3:end,5) C(3:end,6)];
date = datestr(time, 'dd/mm/yyyy HH:MM:SS');
Upto here i'm getting what i need. A sample output is here:
26/03/2013 17:23:24
27/03/2013 07:13:24
27/03/2013 13:13:24
Then when I used this to plot mydata, the plot was wrong as the time axis was not correct. When i checked this with the following script just to see whether correct time is reproduced
d1 = datenum(date);
date_new =datestr(d1,'dd/mm/yyyy HH:MM:SS')
this is what i get.
03/09/0031 17:23:24
02/09/0032 07:13:24
02/09/0032 13:13:24
HH,MM and SS are correct but not the year or month or date. Workspace shows
C <4346x31 double>
d1 <4344x1 double>
date (4344x19 char>
date_new <4344x19 char>
time <4344x6 double>
Any help? Thanks.
0 个评论
采纳的回答
per isakson
2013-4-12
编辑:per isakson
2014-8-13
Try this:
date = '26/03/2013 17:23:24';
d1 = datenum(date);
date_new =datestr(d1,'dd/mm/yyyy HH:MM:SS')
date = '26/03/2013 17:23:24';
d1 = datenum( date, 'dd/mm/yyyy HH:MM:SS' );
date_new =datestr(d1,'dd/mm/yyyy HH:MM:SS')
I get (R2012a)
date_new =
03/09/0031 17:23:24
date_new =
26/03/2013 17:23:24
Doc says:
DateNumber = datenum(DateString) converts date string DateString into
a serial date number. String DateString must be in one of the date
formats 0, 1, 2, 6, 13, 14, 15, 16, or 23, as defined in the reference
page for the datestr function.
I assume that '26/03/2013 17:23:24' is not according to one of these formats ( 0, 1, 2, 6, 13, 14, 15, 16, or 23).
Be careful with "unknown" default values.
更多回答(1 个)
KRUNAL
2014-8-12
编辑:KRUNAL
2014-8-12
Can you post your script u wrote for plotting your 'mydata' against time. I am having some errors in a code that works on similar principle.
I have date in column 1 and time in column 2 and data in column 3. I want to plot date/time against that data. Can anyone tell me how can I do it?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!