An error caused by different versions of MATLAB

Hi Robert,

I ran the OLGModel10 on the HPC, which has MATLAB 2022b installed, and received the following error messages:

Error using EvalFnOnAgentDist_Grid_J
Index exceeds the number of array elements. Index must not exceed 0.

Error in EvalFnOnAgentDist_AggVars_FHorz_Case1 (line 154)
Values=EvalFnOnAgentDist_Grid_J(FnsToEvaluate{ff},ParamCell,PolicyValuesPermute,l_daprime,n_a,n_z,a_gridvals,z_gridvals_J);

Error in EvalFnOnAgentDist_AggVars_FHorz_Case1_PType (line 186)
AggVars_ii=EvalFnOnAgentDist_AggVars_FHorz_Case1(StationaryDist_temp,
PolicyIndexes_temp, FnsToEvaluate_temp, Parameters_temp,
FnsToEvaluateParamNames_temp, n_d_temp, n_a_temp, n_z_temp, N_j_temp,
d_grid_temp, a_grid_temp, z_grid_temp, simoptions_temp);

Error in OLGModel10 (line 272)
AggVars=EvalFnOnAgentDist_AggVars_FHorz_Case1_PType(StationaryDist, Policy,
FnsToEvaluate, Params, n_d, n_a, n_z,N_j, N_i, d_grid, a_grid, z_grid_J,simoptions);

When I replaced AllVars with AllStats, I still encountered similar errors:

Error using EvalFnOnAgentDist_Grid_J
Index exceeds the number of array elements. Index must not exceed 0.

Error in EvalFnOnAgentDist_AllStats_FHorz_Case1_PType (line 393)
ValuesOnGrid_ii=EvalFnOnAgentDist_Grid_J(FnsToEvaluate.(FnsToEvalNames{ff}),CellOverAgeOfParamValues,PolicyValuesPermute_temp,l_daprime_temp,n_a_temp,n_z_temp,a_gridvals_temp,z_gridvals_J_temp);

Error in OLGModel10 (line 273)
AllStats=EvalFnOnAgentDist_AllStats_FHorz_Case1_PType(StationaryDist,Policy,FnsToEvaluate,Params,n_d,n_a,n_z,N_j,N_i,d_grid,a_grid,z_grid_J,simoptions);

However, the model ran perfectly on my desktop with MATLAB 2025b, so I’m unsure what caused the failure under the older MATLAB release.

1 Like

In the HPC server of my university the most recent version installed is R2023b, so I will test this code there and see if it works or not.

1 Like

Hmm, not obvious to me what the error would be caused by (the different Matlab version, but not clear what newer feature is missing).

From a practical perspective, sorry but I only try and maintain support for the current Matlab version. Simply that I have no practical way to go beyond this. If you find a fix and it doesn’t hurt the performance with current version of Matlab I am happy to implement it.

Your other option is to contact your HPC admin and ask if they can update Matlab. In my experience once you ask for the third time (maybe get a friend to also ask, even if it is not important for the friend) they tend to do so with a month or two delay :smiley:

PS. The Intro to OLG models codes are slightly old and don’t use vfoptions.divideandconquer nor vfoptions.gridinterplayer. If you turn these on the codes will be much faster and more accurate. (I am hoping to go through both Intro to Life-Cycle and Intro to OLG early next year and turn these options on everywhere.)

2 Likes

This was my strategy. I was partly successful since they installed R2024b (from R2023b) but then said that it will take more time to install R2025b. Apparently, Matlab has changed some of the installation procedure. I have no idea what is going on behind the scenes: I guess that installing Matlab on a HPC server is not straightforward

2 Likes

I’ll contact the admin to update MATLAB. The error comes from the AggVars or AggStats section—looks like an indexing issue. I’m new to the VFI Toolkit, so I’m still figuring things out. Thanks for the help!

That’s great—thank you! I’m looking forward to your test results.