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
Nested Structures: The nested structure is a structure in which at least one of the members is itself a structure. For illustration, a structure for the line segment may co

Lower Level File I/O Functions: Whenever reading from data file, as long as the data in the file is "regular" the load function works-in another words, the similar type of dat

#qYou will need to examine two of the nine sections of data: one section of qualitative data (choose either Gender or Position) one section of quantitative data (choose either Intr

Core Objects: The Core Objects in MATLAB are the very fundamental graphics primitives. The description can be found under the MATLAB Help: Under the Contents tab, click the Ha

Example of Functions which return values: Calling this function prints the circumference, since there is no way to store the value, hence, it can be used in following computat

Example of Mode When no value appears more often than any other, the smallest value in the vector will be the mode of the vector. >> shortx = [2 5 1 4]; >> mode(shortx

Help function: Function is computing the two values, there are two output arguments in the function header (i.e., area & circum), that are placed in the square brackets [ ]. A

function sortrows - sorting strings: The function sortrows sorts each and every row as a block, or group, and it also will work on numbers. Here in this illustration the rows

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

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