Skip to content

linspace

Vector of equally spaced points between two endpoints.

y = linspace(a, b)
y = linspace(a, b, n)

Returns a row vector of n equally spaced values starting at a and ending at b (both inclusive). Default n is 100 (note: differs from MATLAB’s default of 100 — same here, but check before porting).

The spacing is (b - a) / (n - 1). Useful for generating x-axis grids for plotting and integration.

linspace(0, 1, 5) % [0 0.25 0.5 0.75 1]
linspace(-pi, pi, 100) % grid for plotting trig
linspace(0, 10) % 100 points between 0 and 10
  • logspace — Vector of logarithmically (base-10) spaced points.