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

조회 수: 2 (최근 30일)
johan
johan 2019년 4월 8일
댓글: madhan ravi 2019년 4월 8일
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

채택된 답변

madhan ravi
madhan ravi 2019년 4월 8일
편집: madhan ravi 2019년 4월 8일
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
Guillaume
Guillaume 2019년 4월 8일
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 2019년 4월 8일
Or to use "ismember()" or "==" to directly compare.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Guillaume
Guillaume 2019년 4월 8일
편집: Guillaume 2019년 4월 8일
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
Guillaume
Guillaume 2019년 4월 8일
Ah, well it's even simpler:
xx == '.'
madhan ravi
madhan ravi 2019년 4월 8일
True :)

댓글을 달려면 로그인하십시오.


Adam
Adam 2019년 4월 8일
편집: Adam 2019년 4월 8일
What is wrong with simply
xx == '.'
if xx is a char array rather than a string as it seems to be?

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by