It should most probably be

```
% find position of variables in variable_weights
L_pos=strmatch('L',M_.endo_names,'exact');
q_pos=strmatch('q',M_.endo_names,'exact');
Y_pos=strmatch('Y',M_.endo_names,'exact');
% find position of variables in M_.endo_names
L_pos_M_.endo_names=strmatch('L',M_.endo_names,'exact');
q_pos_M_.endo_names=strmatch('q',M_.endo_names,'exact');
Y_pos_M_.endo_names=strmatch('Y',M_.endo_names,'exact');
weight_grid_L=0:0.1:1; //I want to have this weight on credit fixed at 1. Not sure how to go about it !! Please help !
weight_grid_q=0:0.05:0.5; //Only allow the weights of q and Y to vary from [0, 1]
weight_grid_Y=0:0.1:1;
n_grid_points_L = length(weight_grid_L);
n_grid_points_q = length(weight_grid_q);
n_grid_points_Y = length(weight_grid_Y);
var_L_CcCR=NaN(n_grid_points_L,n_grid_points_q,n_grid_points_Y);
var_q_CcCR=NaN(n_grid_points_L,n_grid_points_q,n_grid_points_Y);
var_Y_CcCR=NaN(n_grid_points_L,n_grid_points_q,n_grid_points_Y);
for grid_iter_L=1:n_grid_points_L
for grid_iter_q=1:n_grid_points_q
for grid_iter_Y=1:n_grid_points_Y
M_.osr.variable_weights(L_pos,L_pos) = weight_grid_L(grid_iter_L);
M_.osr.variable_weights(q_pos,q_pos) = weight_grid_q(grid_iter_q);
M_.osr.variable_weights(Y_pos,Y_pos) = weight_grid_Y(grid_iter_Y);
oo_.osr = osr(M_.endo_names,M_.osr.param_names,M_.osr.variable_indices,M_.osr.variable_weights);
if oo_.osr.error_indicator==0
var_L_CcCR(grid_iter_L,grid_iter_q,grid_iter_Y)=oo_.var(L_pos_M_.endo_names,L_pos_M_.endo_names);
var_q_CcCR(grid_iter_L,grid_iter_q,grid_iter_Y)=oo_.var(q_pos_M_.endo_names,q_pos_M_.endo_names);
var_Y_CcCR(grid_iter_L,grid_iter_q,grid_iter_Y)=oo_.var(Y_pos_M_.endo_names,Y_pos_M_.endo_names);
end
end
end
end
```

because the variances need to be three-dimensional objects if you trace out all the possible combination of three parameters.