I am trying to calculate the residuals (res) for my 19 time series variables. I expect a (nIndices,:) matrix as an outcome from the calculation. The res calculation works perfectly if applied to 1 individual time series, however it does not work if I try to calculate it with a loop for all time series. It will only calculate res for the first time series (thus I get a 1,: matrix instead of nIndices,:). (The nIndices function correctly calculated 19 time series and was applied in the same editor file many times before).
I would appreciate any hints on what I am missing here.
for i=1:nIndices
res = returns(:,i)-mean(returns(:,i));
end