Clear Filters
Clear Filters

Reading in data and plotting the sunrise/sunset time of different dates against the time.

4 views (last 30 days)
Hi
I was wondering if there is a way to plot the sunset time against the date of a month.
I have data that i can get from http://www.stjarnhimlen.se/2011/stockholm.html.
The data for January looks like Translation
Date Dusk Up ?? ?? Down Dawn | Same but for the moon.
Datum Solen Månen
Gry Upp I mer Dekl Ned Skym Upp I mer Dekl Ned *-tid
1 Lö 6:29 8:44 11:51 -23,0 14:59 17:13 6:11 9:10 -23,4 12:06 6:41
2 Sö 6:29 8:44 11:52 -22,9 15:00 17:14 7:20 10:07 -24,2 12:54 6:45
...
Sorry the site is in Swedish, but data I'm interested in is 'Upp'(Up) and 'Ned' (Down) for 'Solen' (Sun).
So I wanna import this and plot the date against the time
plot(date,time)
but when i try to import it the time creates vectors because of the ' : ' and it also complains of the non strings for the days and non english letters.
I did cleaning manually and got this
aa = [
1 8 44 14 59
2 8 44 15 00
...
]
So now we have 'Date' 'hh' 'mm' 'hh' 'mm'. and i thought of maybe using
datenum('aa(:,2):aa(:,3)','HH:MM')
but it doesnt take vector and i have no idea how to plot so it says the time hh:mm in the y axis.
Any ideas?? Thanks

Answers (4)

David
David on 12 Jan 2012
This should work
datenum([num2str(aa(:,2)) repmat(':',size(aa(:,2))) num2str(aa(:,3))],'HH:MM')

Mamed
Mamed on 12 Jan 2012
Hi, that work fine to make read the time, but when i plot i wanna have the axis to read HH:MM (ie 07.00) now it is in the scale 7.3487e5.
up = datenum([num2str(aa(:,2)) repmat(':',size(aa(:,2))) num2str(aa(:,3))],'HH:MM');
do = datenum([num2str(aa(:,4)) repmat(':',size(aa(:,4))) num2str(aa(:,5))],'HH:MM');
plot(aa(:,1),up);

David
David on 12 Jan 2012
Look at
datetick(tickaxis)
this will reformat your datenum into which every date format you like on your axis

Peter Perkins
Peter Perkins on 6 Feb 2018
As Jan points out, the real question here was the plotting. Since this was originally answered six years ago, in versions of MATLAB beginning in R2014b, plotting times and dates became much easier:
Scraping web pages isn't my forte, so I copied the data to a text file, removed blank lines, removed embedded blanks in "-- --", and added column heading for the day-of-month and weekday columns. Given that:
t = readtable('tmp1.txt','HeaderLines',1);
up = timeofday(datetime(t.Upp,'Format','HH:mm')); % convert text -> datetime -> duration
down = timeofday(datetime(t.Ned,'Format','HH:mm'));
date = datetime(2018,1,t.i);
plot(date,up,'bo',date,down,'rx')
Obviously you will have to punch this up a bit to

Categories

Find more on Dates and Time 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!