I am trying to calculate the delta of an option through the binomial model. Nevertheless, I get the following error when running the code:

```
Subscripted assignment dimension mismatch.
Error in Prova (line 57)
Delta(1:idx, idx)= ...
```

The error has to be in one of the last lines in the code. However, I am not able to solve the problem. The code is as follows:

```
%Data
X= 8;
S0= 8;
r= 0.01;
sigma= 0.27;
dt=91/252;
steps=4;
oType='CALL';
earlyExercise=false;
N=10000000;
% Calculate the Cox Ross Rubinstein model parameters
R = exp(r*dt);
u = exp(sigma*sqrt(dt));
d = 1/u;
p = (R-d)/(u-d);
% Loop over each node and calculate the Cox Ross Rubinstein underlying price tree
priceTree = nan(steps+1,steps+1);
priceTree(1,1) = S0;
for idx = 2:steps+1
priceTree(1:idx-1,idx) = priceTree(1:idx-1,idx-1)*u;
priceTree(idx,idx) = priceTree(idx-1,idx-1)*d;
end
priceTree
% Calculate the value at expiry
valueTree = nan(size(priceTree));
switch oType
case 'PUT'
valueTree(:,end) = N*max(X-priceTree(:,end),0);
case 'CALL'
valueTree(:,end) = N*max(priceTree(:,end)-X,0);
end
% Loop backwards to get values at the earlier times
%steps - Gives the "number" of the step (either 1st, 2nd, 3rd...) by calculating the size of the second dimension of priceTree-1
%N.B: priceTree(dim1,dim2) - dim1: position of the node in the step
% - dim2: the step
steps = size(priceTree,2)-1;
for idx = steps:-1:1
valueTree(1:idx,idx) = ...
exp(-r*dt)*(p*valueTree(1:idx,idx+1) ...
+ (1-p)*valueTree(2:idx+1,idx+1));
end
valueTree
% Calculate Delta at expiry-1
Delta=nan(steps,steps);
for idx=1:steps
Delta(idx, steps)= ...
(valueTree(idx,end)-valueTree(idx+1,end))...
/(priceTree(idx,end)-priceTree(idx+1,end));
end
%Calculate Delta
deltasteps=size(priceTree,2)-2;
for idx=deltasteps:-1:1
Delta(1:idx, idx)= ...
(valueTree(1:idx,idx+1)-valueTree(2:idx+1,idx+1))...
/(priceTree(1:idx,idx+1)-priceTree(2:idx+1,idx+1));
end
Delta
```

Can anybody help me, please? Thanks in advance for answering!