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
. Generate the following signal, x(n)=1+cos((25*pi*n)/100),0 Compute the DTFT of x[n] for w=0:0.01:2*pi Plot the Real part, imaginary part, the amplitude and phas

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

Illustration of Sound files: For illustration, the following script generates a subplot which shows the signals from chirp and from train, which is as shown in figure:

Square Matrices: If a matrix has similar number of rows and columns, for illustration, if m == n, the matrix is square matrix. The definitions which follow in this part apply

I have a 400x2 vel.dat and 20x2 xy.dat file, how can i plot a streamslice graph on matlab with this two files.

Displaying expressions: The good-looking function will show such expressions by using exponents; for illustration, >> b = sym('x^2') b = x^2 >> pretty(b)

Creating the structure Variables: Creating a structure variable can be accomplished by simply storing the values in fields by using assignment statements, or by using the stru

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

Subfunctions: Though, it is possible to have more than one function in a given M-file. For illustration, if one function calls the other, the first function would be the prima

Example Exit modular program: In the illustration below, the user  Chose the Limit; -   Whenever prompted for n, entered the two invalid values before finally ente