From the course: Learning MATLAB

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

For loops

For loops

- [Instructor] The for loop executes a group of statements in a loop for a specified number of times. For example, let's have a variable x that ranges from one to four in incremental steps of one. So let's look at the values for this variable. We will have the initial value in the first spot. We will have the incremental step in the second one and we will have the final value in the third one. So if this variable is in between values one to four, we want to calculate the power of three of these variable value which will be another variable called y equals x in power of three. To understand this better, let's see how the logic behind this works using a flow chart. So if x is equal to one, then we ask, is x higher than four, then no, continue the calculation. So the calculation of x in power of three is done and then we add one more to the variable. So x becomes x plus one, and then, now x will become two. So we again ask if x…

Contents