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?

1 visualizzazione (ultimi 30 giorni)
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??

Risposta accettata

dpb
dpb il 24 Nov 2021
Use
ttP=readtimetable('yourfile');
ttPY=retime(ttP,'yearly','mean');
and magic will happen...
  5 Commenti
dpb
dpb il 24 Nov 2021
Modificato: dpb il 24 Nov 2021
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by