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
Finding a sting - function strfind: The function strfind does necessarily similar thing, except that the order of the arguments does make dissimilarity. The common form is str

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

Sorting Vectors of structures: Whenever working with vector of structures, it is very common to sort based on a particular field within the structures. For illustration, recal

Example of Exponential function modular program: In order to view the distinction in the approximate value for e as n increases, the user kept choosing Limit & entering larger

Examine exponential function: The algorithm for the main script program is shown below:  Call a function eoption to show the menu and return the user's choice.  Loop

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 man

Expanding a function: The expand function will multiply out terms, and factor will do the opposite: >> expand((x+2)*(x-1)) ans = x^2 x-2 >> factor(ans)

Illustration of symbolic variable: When, on the other hand, z is a symbolic variable to start with, quotes are not required around the expression, and the words are automatica

Vectors of Structures: In numerous applications, involving database applications, information generally would be stored in the vector of structures, instead of in individual s

Defined a variable in work space: The variables defined in the script will become a part of the workspace: >> clear >> who >> mysummfile    15 >> who