You are calculating ‘N’ and ‘TI’. They may appear to be integers, however they are not. The solution to that is to force them to be integers with the fix function:
Vm_num = zeros(fix(N),fix(TI));
time = zeros(1,fix(TI));
There are other options such as ceil, floor and round, however fix is likely most appropriate here.
Running your code after that correction reveals this one:
and changing that to:
Then an error occurs with this line:
Vm_ana = (lambda*E)*(sinh(x???/lambda)/cosh(L/2*lambda));
and I have no idea what to do with it.
I will be happy to help with it (as well any other problems that may appear) if your code has problems after you correct the ‘Vm_ana’ calculation.