Matlab - verify if a string have any number

hi everyone;
I have a string and i need to verify if there are any number.
for example
str='scramble3'
and i need a answer like, True or 1(to yes) and False or 0(to no)
Thanks

 Accepted Answer

you can use the function regexp.
example:
~isempty(regexp('scramble3','\d'))
would return a 1.
if you leave out the isempty check then it'll return 9 which is the index position of the number.

4 Comments

works. Thank you very much.
Can i ask you something else,
do you know how can i create a new string just keeping the no vowels .
Str2=scrmbl;
thanks
Very simple. so lets say i create a string called VOWELS;
vowels = 'aeiou';
Str1 = 'scramble3';
then if i go:
vowelIndx = ismember(Str1 ,vowels);
i would get [0 0 0 1 0 0 0 1 0]
so then if i make it
Str2 = Str1(~ismember(Str1,vowels));
we'd get Str2 without the vowels selected in vowelIndx.
thank you
i already used
expression='[aeiou]'; startIndex=regexp(str,expression); str(startIndex)=[]; str2=str
i appreciate it :)

Sign in to comment.

More Answers (1)

str='scramble3'
idx=~isempty(regexp(str,'\d','match'))
%or
idx=any(ismember(str,'0':'9'))

Categories

Tags

Asked:

on 7 Aug 2014

Commented:

on 7 Aug 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!