Illustration of for loop, MATLAB Programming

illustration of for loop:

illustration, to print a column of numbers from 1 to 5:

for i = 1:5




This loop can be entered in the Command Window, though like if and switch statements; loops will make more sense in the scripts and functions. In the Command Window, the outcome would appear after the for loop:

>> for i = 1:5








What the for statement accomplished was to print the value of i and then the newline character for each value of i, from 1 through 5 in steps of 1. The first thing which happens is that i is initialized to have the value 1. Then, the action of loop is executed, that is the fprintf statement which prints the value of i (1), and then the newline character to move the cursor down. Then, i is incremented having the value of 2. Later, the action of the loop is executed, that prints 2 and the newline. Then, i is incremented to 3 and which is printed, then i is incremented to 4 and which is printed, and then finally i is incremented to 5 and which is printed. The final value of i is 5; this value can be used once the loop has completed.


Posted Date: 10/19/2012 3:30:48 AM | Location : United States

Related Discussions:- Illustration of for loop, Assignment Help, Ask Question on Illustration of for loop, Get Answer, Expert's Help, Illustration of for loop Discussions

Write discussion on Illustration of for loop
Your posts are moderated
Related Questions
need help in my accounts help

Command Window: To the left of the Command Window, there are 2 tabs for the Current Directory Window and Workspace Window. If the Current Directory tab is selected, the files

Make a vector of 500 random numbers from a normal distribution with mean 2 and standard deviation 5(randn). a After you generate the vector, verify that the sample mean and stan

1;write a matlab of geuss elimination with scaling and pivoting under consideration?

How to Open Simpower: 1. Open MATLAB 2. In the "Command Window" write ' simulink ' and press Enter or click on the Simulink icon. 3. Simulink Library Browser w

1) Identify an equation that describes some chemical process.  Your equation should have at least two parameters, at least one of which should contribute in a non-linear way. He

Write a program in Mathlab for addition of two matrices.

The occurrence of bushfires in the Port Stephens area may be modelled by a Poisson process. The average occurrences of bushfires n is assumed to be either 15 (event A 1 ), 20 (even

Answers should be submitted in an MS Word document. Simulations should accompany answers in a separate MATLAB file. 1)  Queuing Simulator: Consider a communications router that