linspace
Vector of evenly spaced points between two limits.
Category: Language Fundamentals > Matrices and Arrays
Syntax
y = linspace(a, b)
100 points from a to b.
y = linspace(a, b, n)
n points from a to b, endpoints included.
Description
Unlike a:step:b, you choose the number of points rather than the step, and the last point is exactly b with no rounding drift. That makes it the usual way to build a sampling grid for plots and function evaluation: x = linspace(0, 2*pi, 200).
With n below 1 the result is an empty 1-by-0 vector.
Input arguments
a, b- Start and end values.
amay be larger thanb. n- Number of points (default 100). With
n = 1the result isb.
Output arguments
y- Row vector of
nvalues with constant step(b-a)/(n-1).
Example
linspace(0, 1, 5)
linspace(5, 1, 3)
size(linspace(0, 1))
Output
ans = 1×5
0 0.2500 0.5000 0.7500 1.0000
ans = 1×3
5 3 1
ans = 1×2
1 100
Notes
Vector limits (one row of points per element) are not supported: the call raises an error.