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

fprintf('%d\n',i)

end

 

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

fprintf('%d\n',i)

end

1

2

3

4

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
Introduction to File Input/output (LOAD and SAVE): In most cases, the input to a script will come from a data file which has been generated by the other source. It is also use

This problem description is taken from Illingworth and Golosnoy [1]: For physical systems of inhomogeneous composition, di usion is often observed to cause a change of phase, even

The Requirement details of project are as below. I also need detail description for presentation. For the project, given the training dataset ticdata2000.txt use any method you

need help in my accounts help

The IF-ELSE Statement: The if statement selects whether an action is executed or not. Selecting between the two actions, or selecting from numerous actions, is accomplished by

Various commands for get the help: There are various commands which can serve as an introduction to MATLAB and allow you to get the help: info will show contact informatio

a) Develop and submit a power-based MC "SNR" simulator (derived from the voltage-based SNR program provided in MS Powerpoint file) that: i) Uses the following Input: Time period



1. Given these sinusoids: x 1 (t) = 0.5cos(25t+20°),   x 2 (t)=0.85cos(25t+160°) and   x 3 (t)= 0.81cos(25t-145°) (a)  Subplot the phasors X 1 , X 2 and X 3 corresponding t