I have total of 40 years = 40*365 days = 14600 days of rainfall datas. What if I want to represent a total of 40 plots per year, not per day unit?
2 次查看(过去 30 天)
显示 更早的评论
p = textread('Rainfall of Busan (11.5.1981 11.5.2021).txt');
dt = 1;
totalL = 14600;
plot(p)
I have total of 40 years = 40*365 days = 14600 days of rainfall datas.
What if I want to represent a total of 40 plots per year, not per day unit? (I want to show the average annual precipitation.)
Could you help me??
0 个评论
采纳的回答
dpb
2021-11-24
Use
ttP=readtimetable('yourfile');
ttPY=retime(ttP,'yearly','mean');
and magic will happen...
5 个评论
dpb
2021-11-24
编辑:dpb
2021-11-24
NB: textread is deprecated; use textscan or one of the readXXX routines instead for new code.
If your data file doesn't contain the actual dates, but only the preciptation data, then you'll have to create the date externally somehow or you won't be able to average by year...unless you do have as noted precisely 365*40 records and have ignored the leap years in the data set AND the data do begin on Jan 1 of whatever is the beginning year.
If that is the case, then you can use a time-honored "trick" in MATLAB
Yr0=1960; % an arbitrary start year
PYrMn=mean(reshape(P,40,[])).'; % average by column for the 40 years
yr=Yr0+[0:39].'; % create a year vector
plot(yr,PYrMn) % plot the mean annual by year
You could still make the timetable by
ttP=timetable(P,'TimeStep'],days(1),'StartTime',datetime(Yr0,1,1));
where you read in the precipitation data you have and let timetable build the associated rowtimes date vector for you given the starting time and time step.
There are a zillion ways to get there; it all depends on just what you actually have and then what you want.
更多回答(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!