Error when running Dynare from matlab

I run a code from matlab to run dynare with 32 parameters. If I run this code with initial parameters, it runs fine but once I re-estimate these parameters I get error ‘Index matrix exceed dimension’ with a report on the (ghx and ghu) matrix I formed being the error. If I run the code with a try command around dynare it runs fine but ignores the matrix I created which doesn’t give me the real results. Help please.

Please provide a file tp replicate the issue

The matrix error comes from here D=[zeros(nvar,oo_.dr.nstatic) A(:,1:oo_.dr.npred) zeros(nvar,oo_.dr.nfwrd)];
it says the index matrix exceed dimension when the parameters change but if I use my initial parameters, it runs fine.

See [Getting errors from matlab after running dynare)