Matlab for string segmentation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.