Calculete monthly anomalies time series temperature
6 views (last 30 days)
Show older comments
Hi!
I have this time serie (temperature_93_18.txt) and this monthly mean values (MonthlyAverage.txt) (Attached)
I want to calculete the anomalies for each value of the time serie, this mean to substract for each value of Junary of every year the same value from MonthlyAverage.txt data.
Any fast solution?!
3 Comments
Answers (2)
Peter Perkins
on 28 Jul 2021
You are not doing yourself any favors by using raw numeric vectors with no timestamps. This is almost trivial using datetime and a timetable. Here's one way:
>> Temp = readmatrix("temperature_93_18.txt");
>> AvgTemp = readmatrix("MonthlyAverage.txt");
>> year0 = 1993;
>> temps = timetable(Temp,'RowTimes',datetime(year0,1,1:height(Temp)));
>> head(temps)
ans =
8×1 timetable
Time Temp
___________ ____
01-Jan-1993 6.57
02-Jan-1993 6.53
03-Jan-1993 6.14
04-Jan-1993 6.02
05-Jan-1993 6.02
06-Jan-1993 5.92
07-Jan-1993 5.88
08-Jan-1993 6.58
>> Month = ["Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"];
>> avgTemps = table(Month,AvgTemp)
avgTemps =
12×2 table
Month AvgTemp
_____ _______
"Jan" 5.0984
"Feb" 5.2968
"Mar" 4.9642
"Apr" 4.1152
"May" 3.2809
"Jun" 3.0204
"Jul" 2.8472
"Aug" 2.7302
"Sep" 2.4709
"Oct" 2.8043
"Nov" 3.1844
"Dec" 4.2404
>> t = temps;
>> t.Month = month(temps.Time,"shortname");
>> head(t)
ans =
8×2 timetable
Time Temp Month
___________ ____ _______
01-Jan-1993 6.57 {'Jan'}
02-Jan-1993 6.53 {'Jan'}
03-Jan-1993 6.14 {'Jan'}
04-Jan-1993 6.02 {'Jan'}
05-Jan-1993 6.02 {'Jan'}
06-Jan-1993 5.92 {'Jan'}
07-Jan-1993 5.88 {'Jan'}
08-Jan-1993 6.58 {'Jan'}
>> t = join(t,avgTemps,"Key","Month");
>> head(t)
ans =
8×3 timetable
Time Temp Month AvgTemp
___________ ____ _______ _______
01-Jan-1993 6.57 {'Jan'} 5.0984
02-Jan-1993 6.53 {'Jan'} 5.0984
03-Jan-1993 6.14 {'Jan'} 5.0984
04-Jan-1993 6.02 {'Jan'} 5.0984
05-Jan-1993 6.02 {'Jan'} 5.0984
06-Jan-1993 5.92 {'Jan'} 5.0984
07-Jan-1993 5.88 {'Jan'} 5.0984
08-Jan-1993 6.58 {'Jan'} 5.0984
>> temps.Anomaly = t.Temp - t.AvgTemp;
>> head(temps)
ans =
8×2 timetable
Time Temp Anomaly
___________ ____ _______
01-Jan-1993 6.57 1.4716
02-Jan-1993 6.53 1.4316
03-Jan-1993 6.14 1.0416
04-Jan-1993 6.02 0.92161
05-Jan-1993 6.02 0.92161
06-Jan-1993 5.92 0.82161
07-Jan-1993 5.88 0.78161
08-Jan-1993 6.58 1.4816
0 Comments
Image Analyst
on 3 Jul 2021
isoutlier(), rmoutlier(), or mad() should work. Write back if they don't.
3 Comments
Image Analyst
on 6 Jul 2021
Make it easy for people to help you. Give us a start by giving your code to read in the various text files and plot them.
See Also
Categories
Find more on Language Fundamentals 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!