This program has to standardise data from 'LoadLargeDataSetGranese' (it's a dataset). I have to compare different variables in the same dataset.
That's my error:
Index in position 2 exceeds array bounds. Index must not exceed 114. Error in factormodel2 (line 10) Xs(:,i) = (X(:,i) - mean(X(:,i)))/std(X(:,i)); % subtract the mean and divide by std
LoadLargeDataSetGranese
% standardize data
[n,p] = size(X); % number of time observations and variables
Xs = zeros(n,p); % not necessary, but useful for speed
i = 1;
for i = 1:n % loop on variables
i = i + 1;
Xs(:,i) = (X(:,i) - mean(X(:,i)))/std(X(:,i)); % subtract the mean and divide by std
end
% estimate the factors, the factor loadings, the common components
% and the spectral decomposition
[Z, Phi, lambda, chi, R2, SDec] = principalcomponents(Xs, 11);
ExplainedV = 100*cumsum(SDec([1 21 22 37 50 73],:),2);