Reading in data and plotting the sunrise/sunset time of different dates against the time.
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(4 个)
David
2012-1-12
This should work
datenum([num2str(aa(:,2)) repmat(':',size(aa(:,2))) num2str(aa(:,3))],'HH:MM')
0 个评论
David
2012-1-12
Look at
datetick(tickaxis)
this will reformat your datenum into which every date format you like on your axis
0 个评论
Peter Perkins
2018-2-6
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 个评论
另请参阅
类别
在 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!