How to recognize if there is in a character a point '.'?
Mostrar comentarios más antiguos
Dear Matlab community,
Maybe somebody can help me with the following problem. For a project I would if there is a character a point '.' by scanning each element of the character by returning a true (1), false (0) as answer in an array. I tried the following:
xx='00-055.0'
isstrprop(xx,'punct')
ans =
1×8 logical array
0 0 1 0 0 0 1 0
At the moment it also shows e.g. '-', but is there a method to find explicitely the point '.'?
Thank you.
Regards
Respuesta aceptada
Más respuestas (2)
Edit: I misunderstood the question. It's even simpler than what I initially wrote.
Simply:
xx == '.'
If you want to check multiple characters at once, e.g. . and +
ismember(xx, '.+')
--------
Original answer
Simply
contains(xx, '.')
or
any(xx == '.') %probably faster than contains but only work as long as you're searching just for one character
if wanting to check if any of several characters are in xx, e.g. . and +:
any(ismember(xx, '.+')) %are any character of xx member of the set .+ ?
5 comentarios
madhan ravi
el 8 de Abr. de 2019
No,
contains(xx,'.') % would just give logical whether dot is present in xx it doesn't return a logical exaclty how OP wants
Guillaume
el 8 de Abr. de 2019
??
>> xx = 'abcdefgh.dd.d'
xx =
'abcdefgh.dd.d'
>> contains(xx, '.')
ans =
logical
1
Just a scalar logical
madhan ravi
el 8 de Abr. de 2019
Editada: madhan ravi
el 8 de Abr. de 2019
"For a project I would if there is a character a point '.' by scanning each element of the character by returning a true (1), false (0) as answer in an array."
Yes but OP wants the result to be as
ans =
1×8 logical array
0 0 0 0 0 0 1 0
for
xx = '00-055.0'
Guillaume
el 8 de Abr. de 2019
Ah, well it's even simpler:
xx == '.'
madhan ravi
el 8 de Abr. de 2019
True :)
What is wrong with simply
xx == '.'
if xx is a char array rather than a string as it seems to be?
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!