plot time values, datetick

5 vues (au cours des 30 derniers jours)
paul kaam
paul kaam le 4 Fév 2015
Modifié(e) : dpb le 6 Fév 2015
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

Réponses (1)

dpb
dpb le 5 Fév 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 commentaires
paul kaam
paul kaam le 5 Fév 2015
Thanks you for your answer!
unfortunately it is not precisely 15 seconds, i found out. So i have to use the as you state arbitrary start yr/mo/dy. I tried this today and i couldn't get it to work
could you maybe help me out as to how i should do it?
i suppose it would be something like this: dn = datenum(2015,1,25,[column1]);
many thanks
gr Paul
dpb
dpb le 5 Fév 2015
Modifié(e) : dpb le 6 Fév 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...
  1. convert the timestamps to date numbers so are sequential,
  2. compute the difference to find the roll-over locations that indicate the beginning of next day,
  3. 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)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by