For Loops in Matlab - This is a good link to read and learn more about how "for" loops work in Matlab.
I have two quick suggestions for this:
- What is being passed in the "countourf" function is not changing over different iterations of the loop. Hence all the figures will look same. In this case you're passing 'rho' to 'countourf' function which over various iterations of the loop is not changing. You will have to make some changes in the broader code, so that the place where value to 'rho' is being assigned can be brought inside the loop along with it's one level dependencies, in the current function/script, which are helping the variable 'rho' to receive value.
- You would also like to change the 'for' loop declaration so that it starts from 0 and with 'dt' increments in each iteration runs until maximum time 't'. I strongly recommend to learn about 'for' loops from the link mentioned above. For your quick understanding please have a look at the following.
dt = 0.1;
t = 500;
for i = 0:dt:t
This loop starts from 0, and keeps running with 'dt' steps until 't' is hit (runs last time with value of 'i' is equal to 't').