How to count number of letters (including some with special symbols)
조회 수: 1 (최근 30일)
이전 댓글 표시
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!
댓글 수: 4
채택된 답변
Cris LaPierre
2019년 11월 18일
편집: Cris LaPierre
2019년 11월 18일
Ok, so if each entry is on its own row, then I'd do the following.
vals=readtable('ediD_count.xlsx','ReadVariableNames',false);
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!