You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: SimTimeSeriesIndexes_Case2.m
    path of file: ./repos/VFIToolkit-matlab/SimulateTimeSeries/InfHorz
    
    the code of the file until where you have to start completion: function SteadyStateDist=SimTimeSeriesIndexes_Case2(seedpoint,periods, burnin, PolicyIndexes,Phi_aprimeKron, Case2_Type, n_d,n_a,n_z,pi_z)
%Simulates a path based on PolicyIndexes (and Phi_aprime) of length 'periods' after a burn
%in of length 'burnin' (burn-in are the initial run of points that are then
%dropped)

%Phi_aprimeKron is (num_a_vars,d,z,zprime)
%PolicyIndexes is [num_d_vars,n_a,,n_z]

N_d=prod(n_d);
N_a=prod(n_a);
N_z=prod(n_z);
num_d_vars=length(n_d);

tempPolicyIndexes=reshape(PolicyIndexes,[num_d_vars,N_a,N_z]); %first dim indexes the optimal choice for d and aprime rest of dimensions a,z

    
function SteadyStateDist=SimTimeSeriesIndexes_Case2(seedpoint,periods, burnin, PolicyIndexes,Phi_aprimeKron, Case2_Type, n_d,n_a,n_z,pi_z)
%Simulates a path based on PolicyIndexes (and Phi_aprime) of length 'periods' after a burn
%in of length 'burnin' (burn-in are the initial run of points that are then
%dropped)

%Phi_aprimeKron is (num_a_vars,d,z,zprime)
%PolicyIndexes is [num_d_vars,n_a,,n_z]

N_d=prod(n_d);
N_a=prod(n_a);
N_z=prod(n_z);
num_d_vars=length(n_d);

tempPolicyIndexes=reshape(PolicyIndexes,[num_d_vars,N_a,N_z]); %first dim indexes the optimal choice for d and aprime rest of dimensions a,z
PolicyIndexesKron=zeros(N_a,N_z);
for i1=1:N_a
    for i2=1:N_z
        PolicyIndexesKron(i1,i2)=sub2ind_homemade([n_d],tempPolicyIndexes(:,i1,i2));
    end