Step 1 Load Data:
Hopefully you saved your data as a MATLAB binary *.mat file. If so, you simply need to type "load [filename]"
>> load mydata
We should have three variables that you'll be working with:
Step 2 Make a simple plot:
Last time we used a function called mean, which simply takes the arithmetic mean or average of a data. A function works in that it provides an output and accepts input(s). In the case of mean, you need to send in the data you want to average, and what dimension you want to average over. Let's try this two ways:
>> TMEAN1 = mean(T,1);
>> TMEAN2 = mean(T,2);
We used TMEAN1 (which averages over years) and provides 12 data points (one for each month) in exercise 1. In this exercise we will use TMEAN2 which provides one datapoint per year (i.e., the annual mean temperature). Let's now plot this as:
>>plot(years,TMEAN2);
I like the make the line a bit bolder, you can do this in the GUI, or by typing
>>plot(years,TMEAN2,'k','linewidth',2)
Let's now add some labels to the plot so that your friend in a different class will actually be able to read it. We do this with the functions xlabel and ylabel
>>xlabel('Year')
>>ylabel('Annal Mean Temperature (\circC)')
Step 3 Calculate Linear Trend:
We can calculate linear least squares trends for a given time series using a function provided by Dr. A. You can download that function here. Be sure to save it in your working directory and only use it from that directory. Otherwise MATLAB won't "see" it.
>>[trend,sig]=lineartrend(TMEAN2,0.05);
The 0.05 can be modified. It represent the p-value for your significance test. The values that will be returned are
a. trend, reported in units of Celsius per time unit (here in degrees C per year)
b. sig, a binary such that 1 means that trend is statistically significant, and 0 otherwise
I recommend multiplying trend by 10 to get trend in degrees per decade since that is what the assignment asks for :)
If you just want to calculate the linear trend for 1940-2014 you will need to explicitly specify this such by indexing TMEAN2 accordingly:
>>[trend,sig]=lineartrend(TMEAN2(36:120),0.05);
Step 4: Seasonal Trends
To extract summer temperature (June-August), you will need to create a new variable and average over just months 6 (June) to 8 (August):
>> TJJA = mean(T(:,6:8),2);
To extract winter temperature (Dec-Feb) requires a bit more finesse since it is average of December of the previous year with Jan-Feb of the current year. I recommend a three step process
>> TD=T(:,12);
>>TJF=mean(T(:,1:2),2);
>> TDJF=TD(1:119)/3+TJF(2:120)*2/3;
The last line uses years 1-119 for December, giving December 1/3 weight, with years 2-120 for Jan-Feb, giving the average of those months 2/3rd weight.
Hopefully you saved your data as a MATLAB binary *.mat file. If so, you simply need to type "load [filename]"
>> load mydata
We should have three variables that you'll be working with:
- T, which has the size 120 (years) x 12 (months)
- P, which has the size 120 (years) x 12 (months)
- years, which has the size 120 years
Step 2 Make a simple plot:
Last time we used a function called mean, which simply takes the arithmetic mean or average of a data. A function works in that it provides an output and accepts input(s). In the case of mean, you need to send in the data you want to average, and what dimension you want to average over. Let's try this two ways:
>> TMEAN1 = mean(T,1);
>> TMEAN2 = mean(T,2);
We used TMEAN1 (which averages over years) and provides 12 data points (one for each month) in exercise 1. In this exercise we will use TMEAN2 which provides one datapoint per year (i.e., the annual mean temperature). Let's now plot this as:
>>plot(years,TMEAN2);
I like the make the line a bit bolder, you can do this in the GUI, or by typing
>>plot(years,TMEAN2,'k','linewidth',2)
Let's now add some labels to the plot so that your friend in a different class will actually be able to read it. We do this with the functions xlabel and ylabel
>>xlabel('Year')
>>ylabel('Annal Mean Temperature (\circC)')
Step 3 Calculate Linear Trend:
We can calculate linear least squares trends for a given time series using a function provided by Dr. A. You can download that function here. Be sure to save it in your working directory and only use it from that directory. Otherwise MATLAB won't "see" it.
>>[trend,sig]=lineartrend(TMEAN2,0.05);
The 0.05 can be modified. It represent the p-value for your significance test. The values that will be returned are
a. trend, reported in units of Celsius per time unit (here in degrees C per year)
b. sig, a binary such that 1 means that trend is statistically significant, and 0 otherwise
I recommend multiplying trend by 10 to get trend in degrees per decade since that is what the assignment asks for :)
If you just want to calculate the linear trend for 1940-2014 you will need to explicitly specify this such by indexing TMEAN2 accordingly:
>>[trend,sig]=lineartrend(TMEAN2(36:120),0.05);
Step 4: Seasonal Trends
To extract summer temperature (June-August), you will need to create a new variable and average over just months 6 (June) to 8 (August):
>> TJJA = mean(T(:,6:8),2);
To extract winter temperature (Dec-Feb) requires a bit more finesse since it is average of December of the previous year with Jan-Feb of the current year. I recommend a three step process
>> TD=T(:,12);
>>TJF=mean(T(:,1:2),2);
>> TDJF=TD(1:119)/3+TJF(2:120)*2/3;
The last line uses years 1-119 for December, giving December 1/3 weight, with years 2-120 for Jan-Feb, giving the average of those months 2/3rd weight.