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 6:05:55 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

Illustration of Mode When there is more than one value with similar (highest) frequency, then the smaller value is mode. In the case below, as 3 and 8 appear twice in the vecto

Operation on file: We concentrate first on the fgetl function that reads strings from the file one line at a time. The fgetl functions afford more control over how the data is

Rectangle - graphics objects: The other core graphics object is the rectangle that can have curvature added to it (!!). Merely calling the function rectangle without any argum

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

Nested Functions: We have seen that the loops can be nested, that means that one inside of the other, functions can be nested. The terminology for nested functions is that an

Function polyval - interpolation: The function polyval can then be used to compute the polynomial at particular values. For illustration, we could compute at every value in th

Persistent Variables: Generally, whenever a function stops executing, then the local variables from that function are cleared. That means that each and every time a function i

Variable packages: Variable packages are now the vector of structures, hence each and every element in the vector is a structure. To show one element in the vector, an index i

WHILE Loops: The while statement is used as a conditional loop in MATLAB; it is used to repeat an action whenever ahead of the time it is not known how many times the action w