For loops - iterator variable, MATLAB in Engineering

Assignment Help:

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.

 


Related Discussions:- For loops - iterator variable

Ischar function - string, ischar function: The ischar function return ...

ischar function: The ischar function return the logical true if an array is a character array, or logical false if not. >> vec = 'EK127'; >> ischar(vec) ans =

Algorithm for subfunction, Algorithm for subfunction: The algorithm fo...

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

Binary search, Binary Search: The binary search supposes that the vect...

Binary Search: The binary search supposes that the vector has been sorted first. The algorithm is just similar to the way it works whenever looking for a name in a phone direc

Subfunctions, Subfunctions: Though, it is possible to have more than o...

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

Cross product of matrix, Cross Product: The cross or outer product a ×...

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

Solving 2 × 2 systems of equations, Solving 2 × 2 systems of equations: ...

Solving 2 × 2 systems of equations: However this may be easy in a MATLAB, in normal finding solutions to the systems of equations is not. The systems which are 2 × 2 are, thou

Vector operations, Vector operations: As vectors are special cases of ...

Vector operations: As vectors are special cases of matrices, the matrix operations elaborated (addition, subtraction, multiplication, scalar multiplication, transpose) work on

Technique is to create one element - vector, Technique is to create one ele...

Technique is to create one element - vector: Technique is to create one element with the values from one structure, and use repmat to replicate it to the preferred size. Then,

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd