What is the function of the linspace in MATLAB?


Quick Answer

The "linspace" function in MATLAB creates a vector of values that are linearly spaced between two endpoints. The function requires two inputs for the endpoints of the output vector, and it also accepts a third, optional input to specify the number of points to include between the endpoints. If this third input is omitted, the resultant vector includes 100 values.

Continue Reading

Full Answer

The "linspace" function operates similarly to the ":" operator, which allows a user to create a vector between two endpoints with a stepsize of 1. However, the "linspace" function includes greater flexibility, as the number of steps can be specified, allowing intervals of values other than 1.

The syntax for the "linspace" function follows the form "x = linspace (3,11,5);" -- this line of code produces an output vector saved in the variable x comprised of a list of 5 numbers evenly spaced between 3 and 11 -- and the resultant vector is [3, 5, 7, 9, 11]. The semicolon at the end of the line of code suppresses output to the MATLAB command window. Without this semicolon, the resultant vector displays on the screen as the program runs. Even if suppressed, the vector is saved in the variable x.

The inputs to the "linspace" function can be input as number values, as in the example above, and need not be integers. Alternatively, variables can be used as the input values.

Learn more about Computer Programming

Related Questions