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

Comparing strings: There are few functions which compare strings and return logical true when they are equivalent or logical false when not. The function strcmp compares the s

Simplification Functions: There are numerous functions which work with expressions, and simplify the terms. Not all the expressions can be simplified, but the simplify functio

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 from a Function: The following function creates a Figure Window as shown in figure, which shows various types of plots for similar y vector. The vector is passed as a

Example to change the line width from the default: For illustration, to change the line width from the default of 0.5 to 1.5: >> set(hl,'LineWidth',1.5) As long as the

Illustration of finding a sting: Let's enlarge this, and write a script which creates a vector of strings which are phrases. The outcome is not suppressed so that the string

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

Write a program to examine exponential function: We will write a program to examine the value of e and the exponential function. It will be a menu-driven. The menu options wil

Algorithm for subfunction: The algorithm for subfunction askforn is as shown:  Prompt the user for the positive integer n.  Loop to print an error message and reprom