Technology Sharing

MATLAB - String Processing

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

MATLAB - String Processing

String processing functions

The string processing functions in MATLAB are as follows:

Function nameillustrate
eval(string)As a MATLAb command evaluates a string
blanks(n)Returns a string with n spaces
deblankRemove trailing spaces from a string
fevalFind the function value given by the string
findstr(string)Find a string within a string and return the position of the string (starting from 1)
isletterCheck if a character is a letter
isstrCheck if it is a string
isspaceReturns true if there is space.
iasterrReturns the string that last generated a MATLAB error
strcmpString comparison function, returns true if they are the same
strcmpiCompare strings, taking case into account
strrepString Replacement Function
strtokFind the first token in a string
strcatConnection String
strvcatConcatenate strings vertically
strjoinInsert a delimiter between each string
strsplitSplit string based on delimiter
strfindFinding a substring
strmatchFind matching strings
strtrimRemove leading and trailing spaces from a string
upperConvert to uppercase
lowerConvert to lowercase

String or string array construction

String or string array construction can be achieved by directly assigning values ​​to variables. The string content in the expression is written in single quotes. If the content contains single quotes, it needs to be escaped with two single quotes.


>>str1='I don''t konw.'
  • 1
  • 2

The output is:

str1 =
‘I don’t know.’

When constructing a string array, there are two forms: "[]" or "{}". If "[]" is used, the lengths of multiple strings must be the same. If "{}" is used, the lengths of multiple strings are different.Normal array or cell array