i = 2for i = 2:523 if Storage(i-1) >= Stage_1_trigger Outflow = Demand_and_losses if Storage(i-1) + Flow(i) - Outflow < 0 Storage(i) = 0 elseif Storage(i-1) + Flow(i) - Outflow > Initial_storage Storage(i) = Initial_storage else Storage(i) = Storage(i-1) + Flow(i) - Outflow end Storage(i) i = i + 1 else while Storage(i-1)<= Stage_1_exit Outflow = 0.9*Demand_and_losses if Storage(i-1) + Flow(i) - Outflow < 0 Storage(i) = 0 elseif Storage(i-1) + Flow(i) - Outflow > Initial_storage Storage(i) = Initial_storage else Storage(i) = Storage(i-1) + Flow(i) - Outflow end i = i + 1 end endend
Hi, I have this code above. However, when the code exits the while loop, the i value initiates again.
For example, before entering the while loop, i = 5. When exiting the while loop, i = 10. However, when the code finishes with the while loop and goes back to the first for loop, i = 5 again rather than 10. How can I prevent this? Thanks!
Best Answer