
%REMINDER: notice that pause is used on occasion, which means you must
%click in matlab to continue

% section 2.d beginning with using monthly data where earlier in chapter using
% yearly data

%read array of data with year,month,number obs,level
load gsl_mon.txt;


% salt lake level begins in 1903 through 2010
%load 2d array lev for processing
% years will be in rows, months will be in columns
ny=108;
nm=12;
n = ny*nm;

for i=1:ny
for j=1:nm
ic = (i-1)*nm+j;
lev(i,j)=gsl_mon(ic,4)*.3048;
end
end

%compute sample mean and standard deviation for each month
mean_m = mean(lev);
sx_m = std(lev,1);

%plot monthly mean;
figure(1);

bar(mean_m);
axis([1 12 1279.5 1280.5])

%plot level data as a function of time
% define time as year and fraction of year
time = gsl_mon(:,1)+gsl_mon(:,2)/12;

figure(2);

bar(time,gsl_mon(:,4)*.3048)
axis([1905 2010 1277 1284])

%transform GSL level by removing long term monthly means and 
%normalizing by monthly standard deviation
% use matlab matrix algebra- ./ is element divide

mean_array = ones(ny,1)*mean_m;
sx_array = ones(ny,1)*sx_m;
z = (lev - mean_array)./sx_array;

%plot transformed data
figure(3);
%reorder z so that columns are years
zt = transpose(z);

bar(time,zt(:));
axis([1905 2010 -2 2])

%plot cdf of transformed data
figure(4);
cdfplot(zt(:));

