Reading in data and plotting the sunrise/sunset time of different dates against the time.
2 views (last 30 days)
Show older comments
Hi
I was wondering if there is a way to plot the sunset time against the date of a month.
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
0 Comments
Answers (4)
David
on 12 Jan 2012
This should work
datenum([num2str(aa(:,2)) repmat(':',size(aa(:,2))) num2str(aa(:,3))],'HH:MM')
0 Comments
David
on 12 Jan 2012
Look at
datetick(tickaxis)
this will reformat your datenum into which every date format you like on your axis
0 Comments
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')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/181902/image.png)
Obviously you will have to punch this up a bit to
0 Comments
See Also
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!