Main Content

logspace

Generate logarithmically spaced vector

Description

y = logspace(a,b) generates a row vector y of 50 logarithmically spaced points between decades 10^a and 10^b. The logspace function is especially useful for creating frequency vectors. The function is the logarithmic equivalent of linspace and the ‘:’ operator.

example

y = logspace(a,b,n) generates n points between decades 10^a and 10^b.

example

y = logspace(a,pi) generates 50 points between 10^a and pi, which is useful in digital signal processing for creating logarithmically spaced frequencies in the interval [10^a,pi].

y = logspace(a,pi,n) generates n points between 10^a and pi.

Examples

collapse all

Create a vector of 50 logarithmically spaced points in the interval [10^1,10^5].

y = logspace(1,5);

Create a vector of 7 logarithmically spaced points in the interval [10^1,10^5].

y1 = logspace(1,5,7)
y1 = 1×7
105 ×

    0.0001    0.0005    0.0022    0.0100    0.0464    0.2154    1.0000

Create a vector of complex numbers with 8 logarithmically spaced points between 10^(1+2i) and 10^(5+5i).

y = logspace(1+2i,5+5i,8)
y = 1×8 complex
104 ×

  -0.0001 - 0.0010i   0.0029 - 0.0024i   0.0133 + 0.0040i   0.0147 + 0.0497i  -0.1242 + 0.1479i  -0.7150 - 0.0822i  -1.2137 - 2.3924i   4.9458 - 8.6913i

Input Arguments

collapse all

First bound, specified as a numeric scalar. The a argument defines a bound of the interval over which logspace generates points. a can be real or complex, and the other bound, b, can be either larger or smaller than a. If b is smaller than a, then the vector contains descending values.

Data Types: single | double
Complex Number Support: Yes

Second bound, specified as a numeric scalar. The b argument defines a bound of the interval over which logspace generates points. b can be real or complex, and b can be either larger or smaller than the other bound, a. If b is smaller than a, then the vector contains descending values.

Data Types: single | double
Complex Number Support: Yes

Number of points, specified as a real numeric scalar.

  • If n is 1, logspace returns 10^b.

  • If n is zero or negative, logspace returns an empty row vector.

  • If n is not an integer, logspace rounds n down and returns floor(n) points.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a

See Also

|