The task is actually simpler and requires a shorter code. Suppose that we have monthly temperature data for a range of years. Then, it is enough to use two 'for' loops to solve the problem:
a=load('filename.txt');
JanT=a(:,2); % Monthy temperature data for January
Years=a(:,1); % Years in the time series
n=length(JanT); % The size of the original time series
n1=n-19; % This operation is needed for the 'for' loop below
n2=n-9; % This operation is needed for the 'for' loop below
S1=[]; % Initialisation of the sum for the first term of the equation (in the vector form)
for i=1:n1
A=sum((JanT(1:i+9)-mean(JanT(1:i+9))).^2); % Finding of the sums from 1 to 10, 11,...56.
S1=[S1,A]; % Writing of the obtained results into the array
end
S2=[]; % Initialisation of the sum for the second term of the equation (in the vector form)
for j=11:n2
B=sum((JanT(j:n)-mean(JanT(j:n))).^2); % Finding of the sums from 66 to 11, 12,...57
S2=[S2,B]; % Writing of the obtained results into the array
end
Sum=S1+S2; % Finding the sums between all possible sizes of the two parts of the time series
[minsum,imin]=min(Sum) % Finding the minimum sum and the corresponding index when it is achieved
Years=Years+10; % Shifting the years properly to find the year when the minimum sum is achieved
imin=Years(imin) % Attribution of the found index to the year in the original time series