EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Login
Home Data Science Data Science Tutorials Matlab Tutorial Linspace MATLAB

Linspace MATLAB

Priya Pedamkar
Article byPriya Pedamkar

Updated March 24, 2023

Linspace MATLAB

Introduction to Linspace MATLAB

MATLAB is a technical computing language. MATLAB gets its popularity from providing an easy environment for performing and integrating computing tasks, visualizing & programming.

ADVERTISEMENT
Popular Course in this category
MATLAB Course Bundle - 5 Courses in 1 | 3 Mock Tests

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Uses of MATLAB include (but not limited to)

  • Computation
  • Simulation
  • Modeling
  • Data analytics (Analysing and Visualizing data)
  • Prototyping
  • Application development
  • Engineering & Scientific graphics

Linspace Function in MATLAB

In this article, we will understand a very useful function of MATLAB called ‘linspace’. This function will generate a vector of values linearly spaced between two endpoints. It will need two inputs for the endpoints and an optional input to specify the number of points to include in the two endpoints.

Syntax of linspace function:

X = linspace(a1, a2)

Now let us understand this one by one

1. X=linspace(a1,a2)

This function will return a row of a vector of 100(default) linearly spaced points between a1 and a2

  • a1 and a2 can be real or complex
  • a2 can be either larger or smaller than a1
  • If a2 is smaller than a1 then the vector contains descending values

Here is an example to understand this:

Example #1

X = linspace(-1, 1)

It will generate a vector of 100 evenly spaced vectors for the interval [-1, 1]

Output:

 generate a vector

Example #2

X = linspace(2, 3)

It will generate a vector of 100 evenly spaced vectors for the interval [2,3]

Output:

MATLAB console

Example #3

X = linspace(2, 1)

Here a2 is smaller than a1, it will generate a vector of 100 evenly spaced vectors for the interval [2,1] in descending order

Output:

spaced vectors for the interval

2. X=linspace(a1,a2,n)

This function will return a row of a vector of “n” points as specified in input for linearly spaced points between a1 and a2. This function gives control of the number of points and will always include the endpoints specified in the input as well.

The spacing between the points is (a2-a1)/(n-1).

  • If n is 1, the function will return a2 as output
  • If n is zero or negative, the function will return 1by0 empty matrix

Here is an example to understand this:

Example #1

X = linspace(-1, 1, 7 )

It will generate a vector of 7 evenly spaced vectors for the interval [-1, 1]

Output:

Linspace matlab

Example #2

X = linspace(2,3,5)

It will generate a vector of 5 evenly spaced vectors for the interval [2,3]

Output:

Linspace matlab

Example #3

X = linspace(2, 3, 1)

Here n = 1, so the function will return a2 input parameter

Output:

Linspace matlab

Example #4

X = linspace (5, 1, 0)

Here n = 0, so function will return 1X0 empty double row vector

Output:

Linspace matlab

Vector of evenly spaced Complex numbers

X = linspace(2+2i, 3+3i)

Here a1 and a2 are complex numbers, it will generate a vector of complex numbers for 100 evenly spaced points for the interval [2+21, 3+3i]

Output:

Linspace matlab

X= linspace(1+1i, 5+5i, 4)

It will generate a vector of complex numbers with 4 evenly spaced point for the interval [1+1i, 5+5i]

Output:

evenly spaced point

The linspace function in MATLAB provides us with an array/matrix comprising the desired number of values starting from and ending at a declared value. The produced array will have exactly the desired number of terms which will be evenly spaced. The values will be in the range of start and end values passed. So, the linspace function will help us in creating an instantiated matrix or array.

Recommended Articles

This is a guide to Linspace MATLAB. Here we discuss the introduction, Linspace Function in MATLAB and Vector of evenly spaced Complex numbers with examples and outputs. You can also go through our other suggested articles to learn more–

  1. Mean Function in Matlab
  2. Matlab Inverse Function
  3. Swift Operators
  4. Loops in Matlab
  5. Reshape in Matlab | Working | Examples
ADVERTISEMENT
SPSS Course Bundle - 14 Courses in 1 | 5 Mock Tests
34+ Hours of HD Videos
14 Courses
5 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
63+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
HADOOP Course Bundle - 32 Courses in 1 | 4 Mock Tests
125+ Hour of HD Videos
32 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
INFORMATICA Course Bundle - 7 Courses in 1
47+ Hours of HD Videos
7 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW