count number of occurences of character in string?

130 vues (au cours des 30 derniers jours)
Leor Greenberger
Leor Greenberger le 25 Sep 2011
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.

Réponses (3)

Dharanee dharan Mani
Dharanee dharan Mani le 3 Mai 2020
Try using
countnum= count(v,'.');

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

Image Analyst
Image Analyst le 25 Sep 2011
numberOfDots = length(find(v=='.'))

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by