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

조회 수: 1 (최근 30일)
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

답변 (4개)

David
David 2012년 1월 12일
This should work
datenum([num2str(aa(:,2)) repmat(':',size(aa(:,2))) num2str(aa(:,3))],'HH:MM')

Mamed
Mamed 2012년 1월 12일
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 2012년 1월 12일
Look at
datetick(tickaxis)
this will reformat your datenum into which every date format you like on your axis

Peter Perkins
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')
Obviously you will have to punch this up a bit to

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by