count number of occurences of character in string?

74 次查看(过去 30 天)
Is there a function/method for counting the number of times a specific character occurs in a string? Say
v = '30.44.532.56';
This is obviously nonesense, but I would like to check how many times the decimal point occurs so that I can reject if used with a function I wrote. This value would be input into GUIDE gui I am creating, so this is why it's in string format.

回答(3 个)

Dharanee dharan Mani
Try using
countnum= count(v,'.');

Leor Greenberger
Leor Greenberger 2011-9-25
I suppose this will actually work.
v = '30.44.532.56';
length(strfind(v,'.'))

Image Analyst
Image Analyst 2011-9-25
numberOfDots = length(find(v=='.'))

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by