Skip to content Skip to sidebar Skip to footer

3 Ways to Split String in Matlab

How to Split String in Matlab

3 Ways to Split String in Matlab - In various programming sciences we know the term Split String, means separating, cutting or dividing a text into several parts.

There are various techniques for separating this text. Some are based on delimiters like ";", ".", "space" etc.

Others use restrictions on text length, such as "I want to go to the market with Mom", taking only 14 characters to "I want to go".

This knowledge is very useful in processing and manipulating strings in Matlab programming.

Some of these techniques will be described in this article.

3 Cara Memisahkan String Matlab (Split String)
Split String Matlab



A. Split (Split) String Using Delimiter.

The delimiter referred to here is a certain character used for the location of the separator.
 
In the Matlab application there are 2 basic syntaxes that are very often used to separate strings, namely:
  1. >> split(str)
  2. >> split(str,delimiter)

Explanation:
  1. Matlab's "split(str)" syntax will split the string/text based on spaces, then the result will be an Array.

    Example:

    >> split('I want to go to the market with Mother')
    
    ans =
    
      9×1 cell array
    
        {'I'   }
        {'want'    }
        {'to'  }
        {'go'     }
        {'to'  }
        {'the'}
        {'market'    }
        {'with'    }
        {'Mother'    }
  2. Matlab's "split(str,delimiter)" syntax will split the string/text based on the specified delimiter or character.

    Our example will separate the text by the dot "." :

    >> split('I want to go to the market. with Mother', ".")
    ans = 2×1 cell array {'I want to go to the market'}
    {' with Mother' }

B. How to Split a String by Number of Characters or Length of Text

As we discussed at the beginning of the paragraph, we will now separate the text "I want to go to the market with Mom", at the 14th character.
 
So the result is "I want to go".
 
The trick is to put a constraint ("from character" : "to character").
 
Contoh pertama:
>> teks = 'I want to go to the market with Mother';
>> teks = teks(1:14) teks = 'I want to go to'
 
Contoh kedua:
>> teks = 'I want to go to the market with Mother';
>> teks = teks(19:35) teks = 'market with Mother'
 
That's a short tutorial on how to separate strings in the Matlab application, hopefully this can help your project.

Thank you for visiting the website Chip Piko.

If this article was useful, you can share this article using the share button below.

Post a Comment for "3 Ways to Split String in Matlab"