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 Display Text
 

Matlab Display Text

Priya Pedamkar
Article byPriya Pedamkar

Updated March 4, 2023

Matlab Display Text

 

 

Introduction of Display Text in Matlab

To display a text in MATLAB, we use ‘disp function’ which displays the text or value stored in a variable without actually printing the name of the variable. Another way used in MATLAB is to type the name of the variable in the command window after the variable is assigned a value; doing this will display the name of the variable also before its value. ‘Disp function’ can be used to display both numeric and string values stored in a variable.

Watch our Demo Courses and Videos

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

Syntax:

disp (A)

Description:

  • disp (A) will display the value of input variable A without printing the name of the variable
  • For an empty input array, A, disp will return a blank screen i.e. nothing is displayed on the output screen

Let us now understand the code of ‘disp function’ in MATLAB with the help of various examples:

Examples of Matlab Display Text

Following are the examples are given below:

Example #1

In this example, we will learn how to display a simple array in MATLAB using disp function.

Below are the steps to be followed:

  • Initialize the array whose elements we want to display
  • Pass the array as a parameter to the disp function

Code:

A = [15 20 -3 4 -12 0 3 6]

[Initializing the array]

disp(A)

[Passing the above array as an argument to the disp function] [disp function will display all the elements of the input array A]

Input:

A = [15 20 -3 4 -12 0 3 6] disp(A)

Output:

Matlab Display Text-1.1

As we can see in the output, the elements of array A are displayed using disp function. Please note that only the values of A are displayed, and not the variable ‘A’ itself.

Example #2

In this example, we will learn how to display a simple text in MATLAB using disp function.

Below are the steps to be followed:

  • Initialize the string which we want to display
  • Pass the string as a parameter to the disp function

Code:

A = 'Let us learn how to display text in MATLAB'

[Initializing the string to be displayed]

disp(A)

[Passing the above string as an argument to the disp function] [disp function will display the string stored in the variable A]

Input

A = 'Let us learn how to display text in MATLAB'
disp(A)

Output:

Matlab Display Text-1.2

As we can see in the output, the input string is displayed using the disp function. Please note that only the text of A is displayed, and not the variable ‘A’ itself. In the above 2 examples, we used the ‘disp’ function to either display numeric values or text. Next, we will learn how to display values stored in multiple variables.

Example #3

In this example, we will learn how to use the disp function when we have multiple variables.

Below are the steps to be followed:

  • Initialize the variables to be displayed
  • Create a new variable with the above two variables and with any text required in between the variables
  • Pass the variables as parameters to the disp function

Code:

Country = 'India'
Rank = 5

[Initializing the input variables to be displayed]

D = [ Country, ' is ranked ' , num2str(Rank), 'th in terms of nominal GDP' ]

[Creating a variable with the above two inputs and required text in between]

disp(D)

[Passing the above variable as an argument to the disp function] [disp function will display the output of variables Country and Rank with ‘th in terms of nominal GDP’ text in between]

Input:

Country = 'India'
Rank = 5
D = [ Country, ' is ranked ' , num2str(Rank), 'th in terms of nominal GDP' ] disp(D)

Output:

 Matlab Display Text-1.3

As we can see, the output has values that are derived from multiple variables.

Example #4

Let us take another example where we will use disp function to get output displayed out of multiple variables. For this example, we will be combining 3 variables

Below are the steps to be followed:

  • Initialize the variables to be displayed
  • Create a new variable with the above two variables and with any text required in between the variables
  • Pass the variables as parameters to the disp function

Code:

Country = 'India'
Rank1 = 5
Rank2 = 3

[Initializing the input variables to be displayed]

D = [ Country, ' is ranked ' , num2str(Rank1), 'th in terms of nominal GDP and ', num2str(Rank2), 'rd in terms of PPP ']

[Creating a variable with the above two inputs and required text in between]

disp(D)

[Passing the above variable as an argument to the disp function]

Input:

Country = 'India'
Rank1 = 5
Rank2 = 3
D = [ Country, ' is ranked ' , num2str(Rank1), 'th in terms of nominal GDP and ',
num2str(Rank2), 'rd in terms of PPP '] disp(D)

Output:

Matlab Display Text-1.4

As we can see, the output has values that are derived from multiple variables.

Conclusion

  • To display text or numeric values in MATLAB, we use disp function
  • Disp function helps us to get the output displayed without getting the name of the variable
  • Disp function can be used both for a single variable and multiple variables

Recommended Articles

This is a guide to Matlab Display Text. Here we also discuss the syntax and parameters of Matlab display text along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. MATLAB text()
  2. Varargin in Matlab
  3. MATLAB Colon
  4. Matlab zeros()

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