Matlab for string splitting (split)
Matlab the string processing does not have C # powerful, and itself did not provide OO characteristics, you need to rely on other means to accomplish this task.
Here we are using the regular expression functionRegExpof theSplitmode. General Syntax:
S = RegExp (str, char, ' split ')
whichStris the string to be split,Charis the character that is the delimiter (you can use regular expressions). The split result existsSthe.
take the following string of characters as an example
Hello Nocturne Studio
first remove the trailing spaces:
str = deblank (str)
Example1: Set these strings to be tab delimited, so you can do this:
S = RegExp (str, ' \ t ', ' split ')
Example2: These strings are delimited by one or more spaces, and can be described using regular expressions:
S = RegExp (str, ' \s+ ', ' Split ')
this way,S (1) = ' Hello ',S (2) = ' Nocturne ',S (3) = ' Studio '.
Note that the results obtained aboveSis aCelltype variable, each of its elements, such asS (1)is stillCelltype, only toDisplay, it cannot be used directly for string manipulation (such as getting one of these characters), so we need to do it once:
S1 = char (S (1))
such a S1 is a real string that can be used for subsequent operations.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Add one: Character-to-numeric conversion functions in MATLAB : str2num (data);
For example:
> str2num (' 0.00682392 ')
Ans =
0.0068
Supplementary Two: Display accuracy function in MATLAB : format long;
Only change the display format, does not affect the actual in-memory data precision, does not produce the problem of precision reduction
For example ( Next Example ) :
> Format Long
> str2num (' 0.00682392 ')
>ans=
0.006823920000000
> Format Short
>str2num (' 0.00682392 ')
>ans=
0.0068
Matlab for string segmentation