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
Initializing the data structure - Function: Function is shown as:   >> printcylvols(cyls) Cylinder x has a volume of 169.6 Cylinder a has a volume of 100.5

Function strncmp: The function strncmp compares only the first n characters in the strings and ignores the rest. The initial two arguments are strings to compare, and third ar

Illustration of Passing arguments to functions: Here is an illustration of calling this function: >> printrand() The random # is 0.94 As nothing is passed to

Example of file ploting data: As the other example, a data file called 'compsales.dat' stores the sales figures (in millions) for divisions in a company. Each line in the f

Illustration of Set operations: For illustration, given the vectors as shown below: >> v1 = 2:6 v1 = 2  3  4  5  6 >> v2 = 1:2:7 v2 = 1  3  5  7

IS Functions in Matlab: There are many functions which are built into MATLAB which test whether or not something is true; these function names start with the word is. As these

analyzing traffic; determine motion of flow; calculate tracklets; detect abnormalities;

Sound Files: The sound signal is an illustration of a continuous signal which is sampled to result in a discrete signal. In this situation, sound waves traveling through the a

Use of Nested if-else statements: By using the nested if-else to select from among the three possibilities, not all the conditions should be tested. In this situation, if x is

Structures: The Structures are data structures which group together values which are logically related in what are known as the fields of structure. The benefit of structures