Combine strings - MATLAB join - MathWorks España (2024)

Combine strings

collapse all in page

Syntax

newStr = join(str)

newStr = join(str,delimiter)

newStr = join(str,dim)

newStr = join(str,delimiter,dim)

Description

example

newStr = join(str) combines the text in str by joining consecutive elements of the input array, placing a space character between them. str can be a string array or a cell array of character vectors. newStr has the same data type as str.

  • If str is a 1-by-N or an N-by-1 string array or cell array, then newStr is a string scalar or a cell array that contains one character vector.

  • If str is an M-by-N string array or cell array, then newStr is an M-by-1 string array or cell array.

For a string or cell array of any size, join concatenates elements along the last dimension of str with a size that does not equal 1.

example

newStr = join(str,delimiter) combines the text in str and places the elements of delimiter between the elements of str instead of a space character.

If the delimiter argument is an array of different delimiters, and str has N elements along the dimension that is joined, then delimiter must have N–1 elements along the same dimension. The other dimensions of delimiter must have either a size of 1 or the same size as the corresponding dimension of str.

example

newStr = join(str,dim) combines the elements in str along the dimension dim.

newStr = join(str,delimiter,dim) combines the elements in str along the dimension dim and places the elements of delimiter between the elements of str.

Examples

collapse all

Combine Strings in String Array

Create a string array. You can create strings using double quotes.

str = ["Carlos","Sada"; "Ella","Olsen"; "Diana","Lee"]
str = 3x2 string "Carlos" "Sada" "Ella" "Olsen" "Diana" "Lee" 

Combine the strings using the join function. join concatenates the strings from str and places a space character between them. join concatenates along the second dimension, because it is the last dimension with a size that does not equal 1.

newStr = join(str)
newStr = 3x1 string "Carlos Sada" "Ella Olsen" "Diana Lee"

Combine Elements of String Array with Delimiters

Open Live Script

Combine elements in a string array. Instead of spaces, insert different pieces of text between the strings in str.

Create a string array.

str = ["x","y","z"; "a","b","c"]
str = 2x3 string "x" "y" "z" "a" "b" "c"

Concatenate the strings with dashes between them.

newStr = join(str,"-")
newStr = 2x1 string "x-y-z" "a-b-c"

Concatenate the strings with symbols that make the output strings represent equations. The delimiters argument must be a 2-by-2 array because str is a 2-by-3 array.

delimiters = [" + "," = "; " - "," = "];newStr = join(str,delimiters)
newStr = 2x1 string "x + y = z" "a - b = c"

Combine String Array Along Specified Dimension

Open Live Script

Create a string array.

str = ["Carlos","Sada"; "Ella","Olsen"; "Diana","Lee"]
str = 3x2 string "Carlos" "Sada" "Ella" "Olsen" "Diana" "Lee" 

Combine the strings in str along the first dimension. By default, the join function combines strings along the last dimension with a size that does not equal 1. To combine the strings along the first dimension, specify it as an additional input argument.

newStr = join(str,1)
newStr = 1x2 string "Carlos Ella Diana" "Sada Olsen Lee"

Input Arguments

collapse all

strInput text
string array | cell array of character vectors

Input text, specified as a string array or a cell array of character vectors.

delimiterDelimiting characters for joining strings
' ' (default) | character vector | cell array of character vectors | string array

Delimiting characters for joining strings, specified as a character vector, a cell array of character vectors, or a string array. join forms the output string array by combining string elements with delimiters between them.

join inserts all characters in delimiter as literal text, including escaped character sequences.

dimDimension along which to join strings
positive integer

Dimension along which to join strings, specified as a positive integer. If dim is not specified, then the default is the last dimension with a size that does not equal 1.

Output Arguments

collapse all

newStr — Output text
string array | cell array of character vectors

Output text, returned as a string array or a cell array of character vectors. newStr has the same data type as the input text and has a size of 1 along the dimension being joined.

Extended Capabilities

This function fully supports tall arrays. Formore information, see Tall Arrays.

Version History

Introduced in R2016b

See Also

split | regexp | string | splitlines | newline | compose | sprintf | plus

Comando de MATLAB

Ha hecho clic en un enlace que corresponde a este comando de MATLAB:

 

Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.

Combine strings - MATLAB join- MathWorks España (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Combine strings - MATLAB join
- MathWorks España (2024)
Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6058

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.