logo for matrixlab-examples.com
leftimage for matrixlab-examples.com

String Concatenation in Matlab

This video shows how to attach numbers to strings, that is, how to accomplish number to string concatenation.

You can use this technique to make a sequential list of titles, file names... or whenever a variable needs to be put in a string.

This is done with the built-in function num2str and loops. If you type ‘help num2str’ on your Matlab command window, you get the following description:

NUM2STR Convert numbers to a string.
T = NUM2STR(X) converts

the matrix X into a string representation T with about 4 digits and an exponent if required. This is useful for labeling plots with the TITLE, XLABEL, YLABEL, and TEXT commands. 

It means that you then get a string version of the number and can concatenate it to other strings in a logic sequence. A string is a row vector of characters and you can put them inside a pair of brackets. This technique is not recommended to create variables like a1, a2, a3... in that case it’s better to use some type of indexing, like a(1), a(2)... or, in general a(i), where i is a positive integer.

 From 'String Concatenation' to home

 From 'String Concatenation' to 'Matlab Examples'


Long strings: Check writer

footer for string concatenation page