Index in position 1 exceeds array bounds (must not exceed 26)
1 view (last 30 days)
Show older comments
hello guys, i am trying to run the following code but it says "Index in position 1 exceeds array bounds (must not exceed 26)."
theta_post_2=[beta_post_prod1,sigma2_post_prod1];
sigma2_start = 1;
lblx = {'CONSTANT';'Head_Sex'; 'Edu';'HHsize'; 'Offfarm';'Distance_output';'Distance_Input';'Asset_Value';'Plot_Size' ;'Plot_Distance';'Seed_Value' ; 'Remit';'Confid';'Credit';'highfer';'mediumfer';'flatslop';'Slightslop';'Sever_err' ;'Mild_err';'Tenur';'Pulses';'Cereals';'Femalehr';'Malehr';'Improved_Var'};
disp('');
disp(' GIBBS SAMPLER RESULTS ');
disp('=============================================================================');
disp(' Beta sd Prctile 2.5 Prctile 97.5 ');
for i=1:size(theta_post_2,2)
fprintf('%-10s %11.4f %11.4f %11.4f %11.4f\n', ...
lblx{i,1}, [mean(theta_post_2(:,i)), std(theta_post_2(:,i)), prctile(theta_post_2(:,i), 2.5), prctile(theta_post_2(:,i), 97.5)]);
end
disp('-----------------------------------------------------------------------------');
disp(['Number of obs: ' num2str(N)]);
disp(['Number of replications: ' num2str(reps)]);
disp(['Burn-in length: ' num2str(burn)]);
disp(['Starting value: ' num2str(sigma2_start)]);
disp('=============================================================================');
0 Comments
Answers (2)
the cyclist
on 26 Jun 2020
You haven't provided enough info to run your code, which would make debugging much easier. You also didn't tell us which line gives that error.
But, I notice that your varialbe lblx is length 26.
So, I am going to guess that the error comes from this expression:
lblx{i,1}
and that the variable i in the for loop gets to be larger than 26, because theta_post_2 is larger than length 26.
0 Comments
Walter Roberson
on 26 Jun 2020
lblx = {'CONSTANT';'Head_Sex'; 'Edu';'HHsize'; 'Offfarm';'Distance_output';'Distance_Input';'Asset_Value';'Plot_Size' ;'Plot_Distance';'Seed_Value' ; 'Remit';'Confid';'Credit';'highfer';'mediumfer';'flatslop';'Slightslop';'Sever_err' ;'Mild_err';'Tenur';'Pulses';'Cereals';'Femalehr';'Malehr';'Improved_Var'};
That is 26 entries in lblx.
for i=1:size(theta_post_2,2)
fprintf('%-10s %11.4f %11.4f %11.4f %11.4f\n', ...
lblx{i,1}, [mean(theta_post_2(:,i)), std(theta_post_2(:,i)), prctile(theta_post_2(:,i), 2.5), prctile(theta_post_2(:,i), 97.5)]);
end
lblx{i,1} is used up to lblx(size(theta_post_2,2), 1). But as outside observers, we have no reason to know that size(theta_post_,2) is at most 26.
theta_post_2=[beta_post_prod1,sigma2_post_prod1];
I wonder if that should be
theta_post_2 = [beta_post_prod1; sigma2_post_prod1];
0 Comments
See Also
Categories
Find more on Time Series 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!