Illustration of input in a for loop, MATLAB in Statistics

Illustration of Input in a for loop:

In this illustration, the loop variable iv iterates through the values 1 through 3, therefore the action is repeated three times. The action holds of prompting the user for a number and echo printing it with one decimal place.

Rather than of simply echo-printing the numbers, it is frequently necessary to store them in a vector. The one way of accomplishing this is to begin by preallocating the vector and then putting the values in each element, as we saw in earlier example. Here is a function which does this, and returns the resulting vector. The function receives input argument n, and repeats the procedure n times.

777_Illustration of Input in a for loop.png

Here is an illustration of calling this function and storing the resulting vector in a variable known as the myvec.

>> myvec = forinputvec(3)

Enter a number: 44

Enter a number: 2.3

Enter a number: 11

myvec =

44.0000  2.3000  11.0000

Posted Date: 10/19/2012 3:44:16 AM | Location : United States







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

Write discussion on Illustration of input in a for loop
Your posts are moderated
Related Questions
Sequential Search: A sequential search is completed by looping through the vector element-by-element starting from the beginning, looking for the key. Usually the index of the

Types of errors: There are some various kinds of errors which can occur in a program, that fall into the categories of run-time errors, syntax errors, and logical errors. T

Opening and Closing a File: The Files are opened with the fopen function. By the default, fopen function opens a file for reading. If the other mode is preferred, a permission

Example of Vectorizing: Likewise, for an operation on a matrix, a nested loop would be needed; for illustration, supposing a matrix variable mat: [r c] = size(mat); for

Illustration of reading from files: For illustration, suppose that there is a data file 'subjexp.dat' that has on each line a number followed by thecharacter code. The type fu

Location of a rectangle - graphics objects: The location of a rectangle is [x y w h], where x and y are the coordinates of the lower left point, here w is the width, and h is

Areacirc function: The areacirc function can be called from the Command Window as shown here, or from a script. Here is a script which will prompt the user for the radius of o

Tracing: Sometimes, when a program has loops and/or selection statements and is not running properly, it is helpful in the debugging process to know exactly which statements h

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

Illustrations of Sequential search: The two illustrations of calling such function is as shown below: >> values = [85 70 100 95 80 91]; >> key = 95; >> seqsearch