Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get substring to work in matlab?

Tags:

matlab

I apologize if this is a newb question, but I have read the documentation here and it says nothing about having to input any command before using substring.

However, when I try to call it as follows:

substring('hello world', 2)

It gives me the error

??? Undefined function or method 'substring' for input arguments of type 'char'.

What is the correct way to invoke this substring?

like image 985
merlin2011 Avatar asked Apr 21 '13 00:04

merlin2011


People also ask

How do you check if a substring is present in MATLAB?

tf = contains( str , substr ) returns 1 ( true ) if the string str contains the substring substr , and returns 0 ( false ) otherwise. tf = contains( str , substr ,IgnoreCase=true) checks if str contains substr , ignoring any differences in letter case.

How do you slice a string in MATLAB?

newStr = split( str ) divides str at whitespace characters and returns the result as the output array newStr . The input array str can be a string array, character vector, or cell array of character vectors. If str is a string array, then so is newStr .

How do I join two strings in MATLAB?

Concatenate Two String Arrays Strings and character vectors can be combined using strcat . When concatenating strings with character vectors a whitespace will not be added. Concatenate a character vector onto each element of the string array. str3 = strcat(str,', M.D.')

How do you make a string in MATLAB?

String arrays provide a set of functions for working with text as data. You can create strings using double quotes, such as str = "Greetings friend" . To convert data to string arrays, use the string function.


1 Answers

Not to detract from the OP's answer, which actually more directly adresses the question you ask, but assuming all you want to do is extract a certain number of characters from a string, MATLAB's indexing is all you need:

myString = 'Hello, world!';
mySubstring = myString(3:end)
mySubstring =

llo, world!
like image 77
wakjah Avatar answered Oct 04 '22 01:10

wakjah