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 Append
 

Matlab Append

Updated March 8, 2023

Matlab Append

 

 

Introduction to Matlab Append

Matlab append method can be used to append a string and add another string to it. This method is very handy when combining multiple strings and getting a single string as the output.

Watch our Demo Courses and Videos

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

For example, if we take 2 strings, ‘First Name’ and ‘Last Name’, as inputs from the user, later there might be a possibility that we need to combine these 2 strings and get a single string which will give us the full name. This is where we use the append method in Matlab.

Syntax:

  • NewString = append (string1, string2, …. stringN) is used to combine various strings in Matlab. The strings will be combined in the same order as they are passed as arguments.
  • As it is evident from the syntax, we can combine multiple strings using the append method.

Examples of Matlab Append

Given below shows how to combine strings in Matlab using the append method:

Example #1

In this example, we will use the append method to combine 2 strings.

The steps to be followed for this example are:

  • Initialize the strings that are to be combined.
  • Pass the above strings as arguments to the append function.

Code:

  1. string1 = “MATLAB”
[Initializing the 1st string]
  1. string2 = “Append”
[Initializing the 2nd string]
  1. NewString = append(string1, string2)
[Passing the above 2 strings to the append method. Please note that the order of arguments must be the same in which we want the strings to be combined]

This is how our input and output will look like in the Matlab command window:

Input:

Matlab Append 1

Output:

Matlab Append 2

As we can see in the output, we have obtained a string that combines string1 and string2.

In the above example, we saw that the 2 input strings were combined, but there was no space between them in the final output.

Next, we will see how to add a space or any special character between 2 strings.

Example #2

In this example, we will use the append method to combine 2 strings with a space between them.

The steps to be followed for this example are:

  • Initialize the strings that are to be combined.
  • Add an extra space at the beginning of the 2nd string.
  • Pass the above strings as arguments to the append function.

Code:

  1. string1 = “MATLAB”
[Initializing the 1st string]
  1. string2 = “ Append”
[Initializing the 2nd string. Please note that we have added an extra space at the beginning of string2. This is done to get a space in the combined string]
  1. NewString = append(string1, string2)
[Passing the above 2 strings to the append method. Please note that the order of arguments must be the same in which we want the strings to be combined]

This is how our input and output will look like in the Matlab command window:

Input:

combine 2 strings with a space between them

Output:

Matlab Append 4

As we can see in the output, we have obtained a string that combines string1 and string2. If we compare this output with the output in example 1, we will notice that now we have a space between two strings.

In the above examples, we combined 2 strings; next, we will see to combine more than 2 strings using the append method.

Example #3

In this example, we will use the append method to combine multiple strings with a space between them.

The steps to be followed for this example are:

  • Initialize the strings that are to be combined.
  • Add an extra space at the beginning of all the strings, except the first one.
  • Pass the above strings as arguments to the append function.

Code:

  1. string1 = “Let”
[Initializing the 1st string]
  1. string2 = “ us”
[Initializing the 2nd string. Please note that we have added an extra space at the beginning of string2. This is done to get a space in the combined string]
  1. string3 = “ learn”
[Initializing the 3rd string. Again, there is an extra space]
  1. string4 = “ MATLAB”
[Initializing the 4th string]
  1. NewString = append(string1, string2, string3, string4)
[Passing the above 4 strings to the append method. Please note that the order of arguments must be the same in which we want the strings to be combined]

This is how our input and output will look like in the Matlab command window:

Input:

to combine multiple strings with a space between them

Output:

Matlab Append 6

As we can see in the output, we have obtained a string that combines all the input strings.

Example #4

In this example, we will use the append method to combine string arrays of vectors. These character vectors are combined element by element.

The steps to be followed for this example are:

  • Initialize the string arrays that are to be combined.
  • Pass the above string arrays as arguments to the append function.

Code:

  1. Names = [“John” “Sam” “Mark” “Vince”]
[Initializing the 1st string array]
  1. Department = [“ HR” “ Finance” “ Operations” “ Marketing”
[Initializing the 2nd string array]
  1. NewString = append(Names, Department)
[Passing the above 2 string arrays to the append method. Please note that the order of arguments must be the same in which we want the arrays to be combined]

This is how our input and output will look like in the Matlab command window:

Input:

combine string arrays of vectors

Output:

Matlab Append 8

As we can see in the output, we have obtained the combination of 2 string arrays.

Conclusion

Append is used in Matlab to combine 2 or more strings. We can also combine string arrays using the append method. Special characters like ‘space’ can be added if need be.

Recommended Articles

This is a guide to Matlab Append. Here we discuss the introduction to Matlab Append along with examples for better understanding. You may also have a look at the following articles to learn more –

  1. Matlab plot title
  2. Matlab fplot()
  3. Matlab Stacked Bar
  4. Dot Product 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