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
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

ischar function: The ischar function return the logical true if an array is a character array, or logical false if not. >> vec = 'EK127'; >> ischar(vec) ans =

Illustration of Gauss elimination: For illustration, for a 2 × 2 system, an augmented matrix be: Then, the EROs is applied to obtain the augmented matrix into an upper

Matrix definitions: As we know the matrix can be thought of as a table of values in which there are both rows and columns. The most common form of a matrix A (that is sometime

Patch function - graphics objects: The patch function is used to generate a patch graphics object, which is made from 2-dimensional polygons. The patch is defined by its verti

printrectarea function: function call: printrectarea(length, width) function header: function printrectarea(len, wid)   In the function call, there are two argume

calcrectarea subfunction: function call: area = calcrectarea(len,wid); function header: function area = calcrectarea(len, wid)   In the function call, the two arg

Displaying expressions: The good-looking function will show such expressions by using exponents; for illustration, >> b = sym('x^2') b = x^2 >> pretty(b)

Appending variables to the Mat-File: Appending to the file adds to what has been saved in a file, and is accomplished by using the -append option. For illustration, supposing

Illustration of gauss-jordan elimination: An illustration of interchanging rows would be r1 ¬→ r3, that would results: Now, beginning with this matrix, an illustration of sc