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

end

 

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

Application: Menu driven Modular Program Numerous longer, more involved programs which have interaction with the user are menu-driven, that means that the program prints a men

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

Example of Interpolation and extrapolation: The MATLAB has a function to do this, known as polyfit. The function polyfit finds the coefficients of the polynomial of the partic

Illustration of Subfunctions: This is an illustration of running this program: >> rectarea Please enter the length: 6 Please enter the width: 3 For a rectan

Illustration of Variable scope: Running this function does not add any of variables to the workspace, as elaborated: >> clear >> who >> disp(mysum([5 9 1]))

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

Cross Product: The cross or outer product a × b of two vectors a and b is defined only whenever both a and b are the vectors in three-dimensional space, that means that they b

function imread: The function imread can read an image file, for illustration a JPEG (.jpg) file. The function reads color images into a 3-dimensional matrix. >> myimage1

Anonymous Functions: The anonymous function is a very easy, one-line function. The benefit of an anonymous function is that it does not have to be stored in an M-file. This ca