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.
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
44.0000 2.3000 11.0000