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
Consider the shaft-rotor system shown in Figure. Write down the equations of motion. Taking  I= 1 kgm 2 and k=10 kNm/rad, for two special cases (α =0.5 and α = 1000) find as many

The Plot Function: We will begin with a very simple graph of one point using the plot function. The script, plotonepoint, below plots only one point. To do this, at first the

You are asked to create an american option multiplicative binomial model calculator in MatLab. Both put and call options should be valued. Given u, d, S 0 , K, r, and T (the usual

How to simulate a robot

Plot way forms for the following modulation schemes using Matlab: a)      2 ASK                     b)  BFSK                                  c) BPSK          4 ASK

How to make EMG analysis by Matlab?

write a computer program that will provide a user with the equilibrium concentration of vacancies in a metallic element as a function of temperature.Temperature range should be men

The fuel consumption of a certain make of car may not be exactly that rated by the manufacturer. Suppose ten cars of the same model were tested for combined city and highway fuel c

User-Defined Functions which return a Single Value: We have seen the use of many functions in the MATLAB. We have used many built-in functions like fix, sin, abs, double, and

This assignment is motivated by the use of flybys of planets / moons in spacecraft missions to alter a spacecraft's trajectory (flight path). Planetary flybys can be used to not on