MATLAB: How to compute multivariate regression residuals

MATLABmultivariate regression residualsoverwritingregression residuals

I am running a loop to obtain residuals from a number of regressions. I have got 1939 y values(dependent variables). I need a series of residuals for each. I use the following code.
for i=1:1939
stats= regstats(y(:,i),x,'linear', {'beta', 'r'});
end
However, I get only one column of residuals when I checked the stats. I doubt the residuals overwrite on only one column after each regression. Any ideas to solve this problem? Thanks.

Best Answer

Thank you for your answer. Your code works:
for i=1:1939 stats(i)= regstats(y(:,i),f,'linear', {'beta', 'r'}); a(:,i)=stats(i).r; end
Yes, weird but I really have 1939 regressions and number of observations is 252.