Matlab linspace is used to Generate linearly spaced vector.
Syntax for Matlabn Linspace: -
y = linspace(x1,x2) y = linspace(x1,x2,n)
- y = linspace(x1,x2) give a row vector which is made with the 100 points with equal distance between x1 and x2
- y = linspace(x1,x2,n) return the n number of points and these point keep the distance of (x2-x1)/(n-1).
- This Matlab linspace function is very similar to the colon operator, “:” But linspace function in matlab direct control over the number of points and always include the endpoints.
Example of Matlab linspace
Create a vector of 100 evenly spaced points in the interval [-5,10]. y = linspace(-5,10);
Create a vector of 7 evenly spaced points in the interval [-5,7]. y1 = linspace(-5,7,7)
output
Example of Matlab linspace |
Important points : -
- x1 and x2 gives the interval for points which is generated by Matlab linspace.
- Data Types: single | double | datetime | duration
- Complex Number Support: Yes