plot time values, datetick
5 views (last 30 days)
Show older comments
Hi,
I have been struggeling with this all night.
i have two columns of data: column 1 (HH:MM:SS), column 2 (random values) below an example
colmn 1:
09:04:21
09:04:36
09:04:51
09:05:06
09:05:51
09:06:06
colmn 2:
1
2
3
4
5
6
now i want to plot these two colmns as they are, so time on the x-as and the other values on the y-as. i was able to do this with datetick the only problem is that i have a large amount of data measuring for 3 days and so "the time will repeat" and data will stack on eachother so to say the x-as will only go from 00:00:00 to 00:00:00 (only 24 hours)
could it be possible that the time will just go on?
hope someone can help many thanks!
gr Paul
0 Comments
Answers (1)
dpb
on 5 Feb 2015
Add an arbitrary start yr/mo/day field for input to datenum. Or, if the timestamps are all precisely 15 second intervals you can simply create a 3-day long datenum as
>> dn=datenum(2015,1,1,9,4,21+[0:15:3*24*60*60].');
>> datestr(dn(1))
ans =
01-Jan-2015 09:04:21
>> datestr(dn(end))
ans =
04-Jan-2015 09:04:21
>>
2 Comments
dpb
on 5 Feb 2015
Edited: dpb
on 6 Feb 2015
Bummer... :) That does make it a little more complex but it's still not too bad.
What you have to do here then is multi-step process...
- convert the timestamps to date numbers so are sequential,
- compute the difference to find the roll-over locations that indicate the beginning of next day,
- add one for each day between each section.
As example, from the list as I created above--
>> dn=datenum(2015,1,1,9,4,21+[0:15:3*24*60*60].');
>> dn=dn-fix(dn); % convert to the time fraction only
>> newDayIdx=find(diff(dn)<0)+1 % find the day rollover points
newDayIdx =
3584
9344
15104
>> fprintf('%5d %f\n',[(3582:3586).' dn(3582:3586)].')
3582 0.999722
3583 0.999896
3584 0.000069
3585 0.000243
3586 0.000417
>>
So, you need to set the day 0 between 1:newDayIdx(1)-1, day 1 from newDayIdx(1):newDayIdx(2)-1, etc., ... then convert that adjusted vector.
NB: The "+1" in the index is owing to the fact the diff() vector of time differences is one shorter than the original and is missing the first location as dt(1)<--t(2)-t(1)
See Also
Categories
Find more on Calendar in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!