Attempt to grow array along ambiguous dimension - loop error

3 views (last 30 days)
I am trying to calculate standard errors in a loop of regressions that I am performing on mutual funds however when i try to run my code o get the 'Attempt to grow array along ambiguous dimension' error message.
Here is my coding so far:
[r,c]=size(FR);
alpha=zeros(c,1);
x=FR(:,i);
y=isnan(x);
sy=sum(y);
x=x((sy+1):end);
lx=length(x);
X=zeros(lx,5);
X(:,1)=ones(lx,1);
X(:,2:5)=C4F((sy+1):end,:);
beta=inv(X'*X)*X'*x;
alpha(i)=beta(1);
X(:,1) = alpha(lx,1);
CM(i) = cov(X(i));
SE(i) = diag(sqrt(CM(i)));
end
I know that the error first relates to the line 'CM(i) = cov(X(i));' however I am unsure what other way there is to obtain the covariance matrix for every fund in my sample (1600 funds). Does anyone know a way to achieve this or correct my current problem?
Thanks in advance!
  1 Comment
Geoff Hayes
Geoff Hayes on 11 Feb 2017
Daniel - I think that you have omitted some of your code. Do you have a for or while loop? What is CM initialized to? What are the dimensions of cov(X(i)) as it might not be a scalar that you are assuming it to be...

Sign in to comment.

Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!