Function to split string in matlab and return second number -
i have string , need 2 characters returned. tried strsplit
delimiter must string , don't have delimiters in string. instead, want second number in string. number 2 digits.
example: 001a02.jpg use fileparts function delete extension of image (jpg), string: 001a02 expected return value 02
another example: 001a43a . return values: 43
another one: 002a12. return values: 12
all filenames in matrix 1002x1. maybe can use textscan
in second example, gives "43a" result.
(just question doesn't remain unanswered, here's possible approach: )
one way go uses splitting regular expressions (matlab's strsplit
mentioned):
str = '001a02.jpg'; c = strsplit(str,'[a-za-z.]','delimitertype','regularexpression');
results in:
c = '001' '02' ''
in older versions of matlab, before strsplit
introduced, similar functionality achieved using regexp(...,'split')
.
if want learn more regular expressions (abbreviated "regex" or "regexp"), there many online resources (jgi..)
in case, if need take 5th , 6th characters string use:
d = str(5:6);
... , if want convert numbers use:
e = str2double(str(5:6));
Comments
Post a Comment