EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • 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
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Matlab disp
 

Matlab disp

Updated March 6, 2023

Matlab-disp

 

 

Introduction to Matlab disp

Disp function is used in MATLAB to display the output of any code without displaying the input variables. This function can be used in cases where our code is not very long or easy to understand, and there is no need of displaying the input variables.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

For example, if we use the disp function to display a string ‘MATLAB Disp function’ stored in a variable ‘A’, our output will be ‘MATLAB Disp function’. However, if we do not use the disp function, our output will be A = ‘MATLAB Disp function’.

Syntax of the disp function:

disp (A)

Description of the disp function:

disp (A) function is used to display or print the value stored in the variable ‘A’ without printing the name of the variable

Examples of Matlab disp

Let us now understand the code to use the disp function in MATLAB.

Example #1

In this example, we will use the disp function to display elements of a vector. Below are the steps to be followed:

  1. Initialize the input vector
  2. Use the disp function to display the elements of the vector

Code:

A = [3 7 1 8 10] [Initializing an input vector and storing it in a variable ‘A’] disp (A)
[Using the disp function to display the value stored in the variable ‘A’]

This is how our input and output will look like in MATLAB:

Input:

Matlab disp output 1

Output:

Matlab disp output 2

As we can see in the output, we have obtained the value (i.e. elements in our case) stored inside the variable ‘A’ by using the disp function.

 Matlab disp output 3

If we print the output without using the disp function, this is how it will look like:

Please note that in this case, even the variable name is displayed in the output.

Example #2

In this example, we will use the disp function to display elements of a matrix. Below are the steps to be followed:

  1. Initialize the input matrix
  2. Use the disp function to display the elements of the matrix

Code:

A = [3 3 1; 8 0 4; 1 4 9] [Initializing a 3 x 3 input matrix and storing it in a variable ‘A’] disp (A)
[Using the disp function to display the value stored in the variable ‘A’]

This is how our input and output will look like in MATLAB:

Input:

Matlab disp output 4

Output:

As we can see in the output, we have obtained the value (i.e. elements of the matrix in this example) stored inside the variable ‘A’ by using the disp function.

output 5

If we print the output without using the disp function, this is how it will look like:

Please note that in this case, even the variable name is displayed in the output.

output 6

Example #3

In this example, we will use the disp function to display a string. Below are the steps to be followed:

  1. Initialize the input string
  2. Use the disp function to display the string

Code:

A = "Let us learn MATLAB disp function"
[Initializing a string and storing it in a variable ‘A’] disp (A)
[Using the disp function to display the value stored in the variable ‘A’]

This is how our input and output will look like in MATLAB:

Input:

output 7

Output:

output 8

As we can see in the output, we have obtained the value (i.e. a string of words in this example) stored inside the variable ‘A’ by using the disp function.

If we print the output without using the disp function, this is how it will look like:

output 9

Please note that in this case, even the variable name is displayed in the output.

Example #4

In this example, we will use the disp function to display the output of a mathematical expression. Below are the steps to be followed:

  1. Initialize the variables involved in the expression
  2. Use the disp function to display the output

Code:

X = 5
[Initializing the 1st input variable] Y = 10
[Initializing the 2nd input variable] Z = 25
[Initializing the 3rd input variable] A = X * Z / Y
[Mathematical expression to be solved] disp (A)
[Using the disp function to display the value stored in the variable ‘A’]

This is how our input and output will look like in MATLAB:

Input:

output 10

Output:

output 11

As we can see in the output, we have obtained the value of our output stored inside the variable ‘A’ by using the disp function.

If we print the output without using the disp function, this is how it will look like:

output 12

Please note that in this case, even the variable name is displayed in the output.

Conclusion

  1. We use the disp function to display the value stored inside a variable without printing the name of the variable.
  2. It can be used if we want our output to look neat, without any other information except the actual output.

Recommended Articles

This is a guide to Matlab disp. Here we discuss the Examples of Matlab disp along with the code to use the disp function in MATLAB. You may also have a look at the following articles to learn more –

  1. What is Matlab?
  2. Matlab limit
  3. Matlab textread
  4. Impulse Response Matlab

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - 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
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
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 Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW