for loop is endless
Mostrar comentarios más antiguos
Hello all,
I am trying to create a for loop for 10,000 iterations. I start by creating an empty vector which I then plug in into my for loop. The only problem is my for loop is not stopping and I have to force stop the script to run. Secondly, it seems that my forloop is just overwriting each iteration's computation and not appending it to the next row.
Below is an extract of my code
ST1 = 1:1:10000
%ST1 = zeros()
%Step5: Declaring empty ST2 row vector matrix for 20,000 simulations
ST2 = zeros(1,20000);
%Step5: Simulation of n = 10000 neutral paths
for n = 1:10000
ST1 = sadj*exp(r-0.5*(vol^2))*T+vol*sqrt(T)*randn(n);
end
%Step6: Compute the discounted cash flow for each path
CST1 = [1:10000]
for n = 1:10000
CST1 = exp(-r*T)*max(ST1(n)-K)
end
2 comentarios
Jan
el 22 de Mayo de 2022
There are 2 for loops in the code snippet. Which one do you mean?
Mahmoud Galal
el 22 de Mayo de 2022
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!