MATLAB Programming
MATLAB Programming MATLAB Programming
2 Data Types Function Summary MATLAB provides these functions for working with character arrays: • Functions to Create Character Arrays on page 2-64 • Functions to Modify Character Arrays on page 2-64 • Functions to Read and Operate on Character Arrays on page 2-65 • Functions to Search or Compare Character Arrays on page 2-65 • Functions to Determine Data Type or Content on page 2-65 • Functions to Convert Between Numeric and String Data Types on page 2-66 • Functions to Work with Cell Arrays of Strings as Sets on page 2-66 FunctionstoCreateCharacterArrays Function 'str' blanks sprintf strcat strvcat Description Create the string specifiedbetweenquotes. Create a string of blanks. Write formatted data to a string. Concatenate strings. Concatenate strings vertically. Functions to Modify Character Arrays Function deblank lower sort strjust strrep Description Remove trailing blanks. Make all letters lowercase. Sort elements in ascending or descending order. Justify a string. Replace one string with another. 2-64
Characters and Strings Functions to Modify Character Arrays (Continued) Function strtrim upper Description Remove leading and trailing white space. Make all letters uppercase. Functions to Read and Operate on Character Arrays Function eval sscanf Description Execute a string with MATLAB expression. Read a string under format control. Functions to Search or Compare Character Arrays Function findstr strcmp strcmpi strmatch strncmp strncmpi strtok Description Find one string within another. Compare strings. Compare strings, ignoring case. Find matches for a string. Compare the first N characters of strings. Compare the first N characters, ignoring case. Find a token in a string. Functions to Determine Data Type or Content Function iscellstr ischar isletter Description Return true for a cell array of strings. Return true for a character array. Return true for letters of the alphabet. 2-65
- Page 114 and 115: 2 Data Types Floating-Point Numbers
- Page 116 and 117: 2 Data Types isfloat(x) ans = 1 You
- Page 118 and 119: 2 Data Types In this example, 7.5 d
- Page 120 and 121: 2 Data Types 8.881784197001252e-016
- Page 122 and 123: 2 Data Types Note that the order of
- Page 124 and 125: 2 Data Types Complex Numbers Comple
- Page 126 and 127: 2 Data Types NaN MATLAB represents
- Page 128 and 129: 2 Data Types All available formats
- Page 130 and 131: 2 Data Types Integer Functions Func
- Page 132 and 133: 2 Data Types Infinity and NaN Funct
- Page 134 and 135: 2 Data Types 1 0 0 1 0 1 1 0 The MA
- Page 136 and 137: 2 Data Types A(B) ans = 5 15 30 35
- Page 138 and 139: 2 Data Types Characters and Strings
- Page 140 and 141: 2 Data Types name = ['Thomas R. Lee
- Page 142 and 143: 2 Data Types Phoenix length(strings
- Page 144 and 145: 2 Data Types • “Setting Field W
- Page 146 and 147: 2 Data Types Ordered Sequentially s
- Page 148 and 149: 2 Data Types An alternate syntax, t
- Page 150 and 151: 2 Data Types Precision is not usual
- Page 152 and 153: 2 Data Types Note You can specify m
- Page 154 and 155: 2 Data Types operator, specifying t
- Page 156 and 157: 2 Data Types Valid Syntax Invalid S
- Page 158 and 159: 2 Data Types A = 'fate'; B = 'cake'
- Page 160 and 161: 2 Data Types while (any(remainder))
- Page 162 and 163: 2 Data Types Converting from String
- Page 166 and 167: 2 Data Types Functions to Determine
- Page 168 and 169: 2 Data Types Date Strings There are
- Page 170 and 171: 2 Data Types • The day field is a
- Page 172 and 173: 2 Data Types datestr(d) ans = 01-Ma
- Page 174 and 175: 2 Data Types Utility Functions (Con
- Page 176 and 177: 2 Data Types • “Applying Functi
- Page 178 and 179: 2 Data Types where the arguments ar
- Page 180 and 181: 2 Data Types You can access subarra
- Page 182 and 183: 2 Data Types Dynamic Field Names Ex
- Page 184 and 185: 2 Data Types Deleting Fields from S
- Page 186 and 187: 2 Data Types plot(mercury, 'b') plo
- Page 188 and 189: 2 Data Types There are at least two
- Page 190 and 191: 2 Data Types Element-by-element org
- Page 192 and 193: 2 Data Types Nesting Structures A s
- Page 194 and 195: 2 Data Types Cell Arrays A cell arr
- Page 196 and 197: 2 Data Types Operation Syntax Descr
- Page 198 and 199: 2 Data Types 3-by-3 Cell Array Note
- Page 200 and 201: 2 Data Types C5 = 'Jan' 'Feb' 'Mar'
- Page 202 and 203: 2 Data Types of an array without re
- Page 204 and 205: 2 Data Types Createa1-by-2arraywith
- Page 206 and 207: 2 Data Types ans = 7 ans = 2 ans =
- Page 208 and 209: 2 Data Types 3 4 B = reshape(A, 6,
- Page 210 and 211: 2 Data Types A{1,1} = [1 2; 3 4]; A
- Page 212 and 213: 2 Data Types [5x5 double] {2x2 cell
Characters and Strings<br />
Functions to Modify Character Arrays (Continued)<br />
Function<br />
strtrim<br />
upper<br />
Description<br />
Remove leading and trailing white space.<br />
Make all letters uppercase.<br />
Functions to Read and Operate on Character Arrays<br />
Function<br />
eval<br />
sscanf<br />
Description<br />
Execute a string with <strong>MATLAB</strong> expression.<br />
Read a string under format control.<br />
Functions to Search or Compare Character Arrays<br />
Function<br />
findstr<br />
strcmp<br />
strcmpi<br />
strmatch<br />
strncmp<br />
strncmpi<br />
strtok<br />
Description<br />
Find one string within another.<br />
Compare strings.<br />
Compare strings, ignoring case.<br />
Find matches for a string.<br />
Compare the first N characters of strings.<br />
Compare the first N characters, ignoring case.<br />
Find a token in a string.<br />
Functions to Determine Data Type or Content<br />
Function<br />
iscellstr<br />
ischar<br />
isletter<br />
Description<br />
Return true for a cell array of strings.<br />
Return true for a character array.<br />
Return true for letters of the alphabet.<br />
2-65