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
Problem: A function is given by Y= 2x3 + 3 x2 -12x + 5 a determine the finite values of x at which any local maximum of minimum occur and determine the corresponding val

A filter described by the equation:    y(n) = x(n) + x(n-1) + 0.9 y(n-1) - 0.81 y(n-2) (a) Find the transfer function H(z) for the filter and find the poles and zeros of the fil

how to display any words to the edittor

how to design a digital fir filter using anfis in matlab.get the code for that.

Printing Vectors and Matrices: For vector, if the conversion character and newline character are in the format string, it will print in a column in spite of of whether the vec

kind in geometric calculity in space AREA. >

Read the document and quote me ... https://www.dropbox.com/s/pvq4f45fpwajibi/Course_wk%20_2013_.pdf

You are a quant analyst reporting directly to a portfolio manager. Your manager requires you to generate a simple code to compute several statistics for the following potential por

1) Convert the table into format convenient for the processing with MATLAB. 2) Prepare a program that perform K Nearest Neighbours algorithm using Euclidian distance. (Your prog