"Out of bounds" error when computing posterior moments

Dear experts,

During estimation (Dynare 6.1), I get an error if I try to compute posterior moments (using moments_varendo in the estimation command) and at the same time specify the number of draws to be different from the default setting (e.g. set sub_draws=2000):

Index in position 1 exceeds array bounds. Index must not exceed 458.

Error in selec_posterior_draws (line 148)
                M_ = set_parameters_locally(M_,pdraws{i,1});

Error in posterior_analysis (line 32)
    selec_posterior_draws(M_,options_,oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state,estim_params_,SampleSize,drsize); %save draws to disk

Error in compute_moments_varendo (line 100)
            oo_ = posterior_analysis('variance', var_list_{i}, var_list_{j}, NumberOfLags, options_, M_, oo_, estim_params_);

The code runs perfectly if sub_draws is left unspecified (with a default value of 1200?). Unfortunately, I cannot share the code, but the estimation command includes the following options:

estimation(..., mh_replic=400000,mh_nblocks=1,mh_tune_jscale=0.33,mh_drop=0.5,sub_draws=2000,moments_varendo)

This results in about 125k accepted draws, from what I can see. And I would have expected that 2000 of these could be used to compute moments without problems. Am I missing something here, or could this be a bug?

Dear Drago,
thanks for reporting this. 馃悰 selec_posterior_draws.m: correct index (bug introduced in dc9560e6) (!2307) 路 Merge requests 路 Dynare / dynare 路 GitLab should fix the issue. Can you please try whether it works?

Awesome, Johannes, that seems to work! I will run the full estimation from scratch later just to be sure, but so far it all looks good. Thanks for the quick follow-up.