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
Example of Function stubs: The three functions have not so far been written, though, therefore the function stubs are put in place so that the script can be executed and teste

fscanf function - file function: The fscanf reads matrix variable mat columnwise from the file specified by fid. The 'format' involves conversion characters much similar to th

Example of sorting strings: To sort a cell array of strings, also the sort function is used. The illustration is as follows, >> engcellnames = {'Chemical','Mechanical',.

Vectorizing: In most of the cases in MATLAB, loops are not essential. As MATLAB is written specifically to work with the vectors and matrices, most operations can be completed

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

bjjh

Median The median is defined only for a data set which has been sorted first, that means that the values are in order. The median of a sorted set of data values (n) is defined

Vectors of nested structures: The Combining vectors and nested structures are possible to have a vector of structures in which several fields are structures themselves. Here i

Representing Logical true and False: It has been stated that expressions which are theoretically true really have the integer value of 1, and expressions which are theoretical

Properties of the text box - graphics objects: By using get will show properties of the text box, the illustration is as shown below: >> get(thand)   BackgroundColor