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
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

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

Mode The mode of a data set is the value which appears most often. The built-in function in a MATLAB for this is known as the mode. >> x = [9 10 10 9 8 7 3 10 9 8 5 10];

Logical errors: The Logical errors are more complicated to locate, as they do not result in any error message. The logical error is a mistake in reasoning by the programmer, b

#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

Working of Editor and debugger: Editor/Debugger, or commands can be typed from Command Window. For illustration, the dbstop command below will set a breakpoint in the fifth li

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

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

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

Debugging Techniques: Any error in the computer program is called a bug. This word is thought to date back to the 1940s, whenever a problem with an early computer was found to