MATLAB: The variable Edj appears to change size consider preallocating

Optimization Toolboxpreallocating

VV(1:size(temp,1),d)=temp;
for j=1:n
E(d,j) = y(j,:)*VV(s+1:s+m,d) / (x(j,:)*VV(1:s,d));
end
Ecros =sum(Edj)/n
End

Best Answer

The size of your matrix changes at every iteration. Make zero matrix before looping. For example:
Edj = zeros(d,n);
*edited for corrections from Image Analyst and Jacob Muvingi