| Creating Strings with Concatenation Strings are often created by concatenating smaller elements together (e.g., strings, values, etc.). Two common methods of concatenating are to use the MATLAB® concatenation operator ([ J) or the sprintf function. The second and third line below illustrate both of these methods. Both lines give the numChars = 28; s = ['There are 1 int2str(numChars| 1 characters here'] s = sprintf('There are %d characters here\n', numChars) For more information: See and Converting from Numeric to String in the MATLAB Programming Fundamental.- documentation. Comparing Methods of Concatenation When building strings with concatenation, sprintf is often preferable to [ ] because • It is easier to read, especially when forming complicated expressions " It gives you more control over the output format " It often executes more quickly You can also concatenate using the strcat function, However, for simple concatenations, sprintf and [ ] are faster. |