For loops - iterator variable, MATLAB in Engineering

For Loops which do not use an iterator Variable in the action:

In all the illustrations that we seen so far, the value of the loop variable has been used in same way in the action of the for loop:

We have printed the value of i, or added it to a sum, or multiplied it by the running product, or used it as an index into the vector. It is not always essential to really use the value of the loop variable, though. At times the variable is easily used to iterate, or repeat a statement at specified number of times. For e.g.,


for i = 1:3

  fprintf('I will not chew gum\n')



Generates the output:

I will not chew gum

I will not chew gum

I will not chew gum


The variable i is compulsory to repeat the action three times, even though the value of i is not used in the action of the loop.


Posted Date: 10/19/2012 3:40:43 AM | Location : United States

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

Write discussion on For loops - iterator variable
Your posts are moderated
Related Questions
Function iscellstr - string function: The function iscellstr will return the logical true when a cell array is a cell array of all the strings, or logical false if not. >>

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

Function used in sound files: The MATLAB has numerous other functions which let you read and play sound or audio files. In the audio files, sampled data for each audio channel

Interpolation and extrapolation: In most cases, it is desired to estimate values other than at the sampled data points. For illustration, we may want to estimate what the temp

Forward elimination: In forward elimination, we want to obtain a 0 in the a 21 position. To accomplish this, we can alter the second line in the matrix by subtracting from it

Displaying the cell arrays: There are several techniques of displaying the cell arrays. The celldisp function shows all elements of the cell array:   >> celldisp(cellro

Splits a string : The strtok function splits a string into pieces; it can be called in many ways. The function receives one string as an input argument. It appears for the fir

Changing Case: The MATLAB has two functions which convert strings to all uppercase letters, or all lowercase, known as the upper and lower. >> mystring = 'AbCDEfgh';

Plotting File data: It is frequently essential to read data from a file and plot it. Generally, this entails knowing the format of the file. For illustration, let us suppose t

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