Nested for loops, MATLAB in Statistics

Nested for Loops:

The action of a loop can be any of the valid statement(s). Whenever the action of a loop is the other loop, this is known as nested loop.

As an illustration, a nested for loop will be elaborated in a script which will print a box of *'s. The variables in the script will identify how many rows and columns to print. For illustration, if rows have the value 3, and columns have the value 5, the output would be:

 

*****

*****

*****

 

As the lines of output are controlled by printing the newline character, the fundamental algorithm is:

For every row of output,

- Print the needed number of *'s

- Shift the cursor down to the next line (print the '\n')

985_Nested for Loops.png

2185_Nested for Loops1.png

 

Posted Date: 10/19/2012 3:46:25 AM | Location : United States







Related Discussions:- Nested for loops, Assignment Help, Ask Question on Nested for loops, Get Answer, Expert's Help, Nested for loops Discussions

Write discussion on Nested for loops
Your posts are moderated
Related Questions
Illustration of tracing a error: The one way of following the flow of function, or tracing it, is to use the echo function. The echo function, that is a toggle, will show each

Rectangle - graphics objects: The other core graphics object is the rectangle that can have curvature added to it (!!). Merely calling the function rectangle without any argum

Illustration of Indexing: Though, rather than of creating the index vector manually as shown here, the process to initialize the index vector is use to a sort function. The al

Logical Built-In Functions: There are built-in functions in the MATLAB which are useful in conjunction with vectors or matrices of all logical true or false values; two of the

Advanced File Input and Output: In that section, we saw how to read the values entered by user using the input as well as the output functions disp and fprintf, that shows inf

Operation on file: We concentrate first on the fgetl function that reads strings from the file one line at a time. The fgetl functions afford more control over how the data is

Function Stubs: The other common debugging method, which is used when there is a script main program which calls many functions, is to use the function stubs. A function stub

Example of sorting strings: To sort a cell array of strings, also the sort function is used. The illustration is as follows, >> engcellnames = {'Chemical','Mechanical',.

Indexing: The Indexing is an alternate to sort a vector. With indexing, the vector is left in its original order. An index vector is used to point values in the original vecto

Example of customizing plots: As the other illustration of customizing plots, the pieces of a pie chart can be "exploded" from the rest. In this situation, the two vectors are