For loop, MATLAB in Engineering

FOR Loop:

The for loop, or the for statement, is used whenever it is essential to repeat statement(s) in the script or function, and whenever it is known ahead of time how many times the statements will be repeated. The statements which are repeated are termed as the action of the loop. For illustration, it might be known that the action of the loop will be repeated five times. The terms used are that we iterate through the action of the loop five times.

The variable which is used to iterate through values is termed as the loop variable, or an iterator variable. For illustration, the variable may iterate through the integers 1 through 5 (example, 1, 2, 3, 4, and then 5). Though variable names in common must be mnemonic, it is general for an iterator variable to be given the name i (and if more than one iterator variable is required, i, j, k, l, etc.) This is historical, and is since of the way integer variables were named in the FORTRAN.

Though, in MATLAB both i & j are built-in values for  1 - , therefore using either as a loop variable will override that value. If this is not an issue, then it is acceptable to use i as a loop variable.

The common form of the for loop is as shown below:

for loopvar = range

action

end

where loopvar is the loop variable, range is the range of values by which the loop variable is to iterate, and the action of loop contains all  the statements up to the end. The range can be identified by using any vector, but usually the simplest way to identify the range of the values is to use the colon operator.

Posted Date: 10/19/2012 3:30:03 AM | Location : United States







Related Discussions:- For loop, Assignment Help, Ask Question on For loop, Get Answer, Expert's Help, For loop Discussions

Write discussion on For loop
Your posts are moderated
Related Questions
Execute a exponential function program: Running the script will take up the menu as shown in the figure: Then, what happens will totally depend on which button(s) the

Matrix Multiplication: The Matrix multiplication does not mean multiplying term by term; and it is not an array operation. The Matrix multiplication has a very particular mean

Uses of Function handles: The Function handles can also be generated for functions other than anonymous functions, both built-in & user-defined functions. For illustration, th

Algorithm for subfunction: The algorithm for subfunction askforn is as shown:  Prompt the user for the positive integer n.  Loop to print an error message and reprom

Inverse of square matrix: The inverse is, hence the result of multiplying the scalar 1/D by each and every element in the preceding matrix. Note that this is not the matrix A,

Reading from a Mat-File: The load function is used to read from various types of files. As with save function, by default the file will be supposed to be a MAT-file, and load

Illustration sorting vectors of structures: This function sorts the structures depend only on the price field. A more common function is shown next, that receives a string whi

Simplification Functions: There are numerous functions which work with expressions, and simplify the terms. Not all the expressions can be simplified, but the simplify functio

Illustration of Image processing: This displays that there are 64 rows, or in another word, 64 colors, in this specific colormap. It also displays that the first five colors a

Passing arguments to functions: In all these functions examples faraway, at least one of the arguments was passed in the function call to be the value(s) of the equivalent inp