MATLAB Programming Tips - The MathWorks - #39

/ 66


catalogue search
P. 01
P. 02
P. 03
P. 04
P. 05
P. 06
P. 07
P. 08
P. 09
P. 10
P. 11
P. 12
P. 13
P. 14
P. 15
P. 16
P. 17
P. 18
P. 19
P. 20
P. 21
P. 22
P. 23
P. 24
P. 25
P. 26
P. 27
P. 28
P. 29
P. 30
P. 31
P. 32
P. 33
P. 34
P. 35
P. 36
P. 37
P. 38
P. 39
P. 40
P. 41
P. 42
P. 43
P. 44
P. 45
P. 46
P. 47
P. 48
P. 49
P. 50


See other catalogues for The MathWorks

Text version of the page
Strings
In this section...
''Crcating Strini^ wiLl'i Concatenation" on page 1-31 "Comparing Methodw of Ooncatenation" on page 1-31 "Store Arrays of Strings in a Celi Array" on page 1-32 ''Convertirig l'.etween Sli'ing.s and (.'oli Arrays" on page 1-32 "Search and Keplace Csing liegiilar Kxpressions" on page 1-32
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.
1-31

pageCatalog pdf di En 2012-06-22-01