nsalg.blogg.se

For loops matlab
For loops matlab







for loops matlab

Now we increment i by 2 i had a value of 4 we increment by 2 and the new value of i is equal to 6 and this begins our third and final loop pass and that is because our current value of i is equal to 6 which is greater than 4 that statement is true and our loop terminates with the endstatement. So the value of 16 is now assigned to x that completes our second loop pass.

for loops matlab

So x is equal to x= i 2 and as the value of I is now 4 so the square will become 16. Now our current value of i is 4 which is not greater than 4 the statement is false and now we assign a new value to x. Next we increment I by 2 so i now has a value of 4 and we begin our second loop pass. So that is the value assigned to x and that completes our first loop pass.

for loops matlab

Let’s take a look at a flow chart of our example which can help demonstrate each loop pass our loop variable i has an initial value of 2 and this initial value of I is not greater than our final value of 4 that statement is false and so we assign a value to x which is equal x= i 2 now as the value of I = 2 so the value of x will be equal to 4. In this case i is our loop variable i has an initial value of 2 an incremental or step value of 2 in a final or terminating value of 4 and for each value of I our statement is evaluated as x= i 2.









For loops matlab