MATLAB Answers

## How to recognize if there is in a character a point '.'?

Asked by johan

### johan (view profile)

on 8 Apr 2019
Latest activity Commented on by madhan ravi

### madhan ravi (view profile)

on 8 Apr 2019
Accepted Answer by madhan ravi

### madhan ravi (view profile)

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

#### 0 Comments

Sign in to comment.

## 3 Answers

### madhan ravi (view profile)

Answer by madhan ravi

### madhan ravi (view profile)

on 8 Apr 2019
Edited by madhan ravi

### madhan ravi (view profile)

on 8 Apr 2019
Accepted Answer

contains(regexp(xx,'.','match'),'.')
%or
strcmp(regexp(xx,'.','match'),'.')
%or
cellfun(@(x)x=='.',regexp(xx,'.','match'))
Gives:
ans =
1×8 logical array
0 0 0 0 0 0 1 0

#### 4 Comments

Show 1 older comment
madhan ravi

### madhan ravi (view profile)

on 8 Apr 2019
No!, each character is split forming a cell array finally to attain logical array.
Guillaume

### Guillaume (view profile)

on 8 Apr 2019
Well, then you don't need to use a regular expression engine to split a char vector into a cell array of individual characters
num2cell(xx)
will do the job faster.
madhan ravi

### madhan ravi (view profile)

on 8 Apr 2019
Or to use "ismember()" or "==" to directly compare.

Sign in to comment.

### Guillaume (view profile)

Answer by Guillaume

### Guillaume (view profile)

on 8 Apr 2019
Edited by Guillaume

### Guillaume (view profile)

on 8 Apr 2019

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 .+ ?

madhan ravi

### madhan ravi (view profile)

on 8 Apr 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

### Guillaume (view profile)

on 8 Apr 2019
Ah, well it's even simpler:
xx == '.'
madhan ravi

### madhan ravi (view profile)

on 8 Apr 2019
True :)

Sign in to comment.

Answer by Adam

on 8 Apr 2019
Edited by Adam

### Adam (view profile)

on 8 Apr 2019

What is wrong with simply
xx == '.'
if xx is a char array rather than a string as it seems to be?

#### 0 Comments

Sign in to comment.