how many times will this loop execute in matlab

To determine how many times a loop will execute in Matlab, you need to know the initial value of the loop control variable, the final value of the loop control variable and the amount by which the loop control variable is incremented or decremented during each iteration of the loop. You can then use this information to determine the number of times the loop will execute using the following equation:

main.m
Number of loop iterations = (Final value - Initial value) / Increment
70 chars
2 lines

Here is an example loop that counts from 1 to 10 in increments of 1:

main.m
for i = 1:10
    disp(i)
end
29 chars
4 lines

The number of loop iterations in this case is:

main.m
(10 - 1) / 1 = 9
17 chars
2 lines

So the loop will execute 9 times.

related categories

gistlibby LogSnag