# How to count number of letters (including some with special symbols)

2 views (last 30 days)
Edi D on 18 Nov 2019
Commented: Edi D on 18 Nov 2019
Hi,
I have an Excel file from which I want to read the entire first column into Matlab and have as an output how many times given letters occur.
However, the problem is that some of the letters have an apostrophe attached to them, for example:
m'
s
a
s'
In the string above, s should be treated as a separate thing which has nothing in common with s'. So the frequency should show 1 for each of the letters, i.e.:
m' 1
s 1
a 1
s' 1
I have tried many things which I found of this forum but none of them has worked so far. One of the basic problems I encountered was loading in the file into Matlab due to the apostrophe, not to mention creating a proper table with frequency.
I would be very grateful for some help!

Show 1 older comment
Edi D on 18 Nov 2019
in a modified version (no uppercase letters and I got rid of averaging and percentages).
I was also trying to adapt Andrei's advice from here https://uk.mathworks.com/matlabcentral/answers/69568-how-to-count-certain-characters-in-a-word but had no idea what to do with the apostrophe - even when I was doing copy-paste of my input using this code.
Cris LaPierre on 18 Nov 2019
What does your input data look like?
Edi D on 18 Nov 2019
It’s an Excel file (or .data if not converted) with the first column which I need to sort out with respect to frequency. A few first rows from the first column look like that: m' s a s' f1 k
So there is quite a mixture of alphanumeric and alpha-special-symbol things. Altogether there is 9 types of these (I listed 6 above), each single one occupying 1 row. The entire file has over 1000 rows in total so the above is just a fraction of the file contents.

Cris LaPierre on 18 Nov 2019
Edited: Cris LaPierre on 18 Nov 2019
Ok, so if each entry is on its own row, then I'd do the following.
cnts=groupsummary(vals,"Var1")
I've attached what I'm using as a data set. It looks like this:
vals =
Var1
____
'm''
's'
'a'
's''
'f1'
'k'
's'
'a'
's''
'a'
...
The result is a table of unique values found in the first variable, and the number of times it was found in the second.
cnts =
Var1 GroupCount
____ __________
'a' 4
'f1' 2
'k' 2
'm'' 1
's' 3
's'' 4

#### 1 Comment

Edi D on 18 Nov 2019
Thank you very much for your help!!! It works great