Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting english letter

Status
Not open for further replies.

ill2000m

Electrical
Oct 7, 2003
7
I have written a M file which allows me to sort the frequencies with which each symbol appears in x,
from most frequent to least frequent... but i would like to sort frequecy of appearence of the english letter (a-z)inside x ...

e.g.
x =[A,A,B,C,]

so the result i want to get on the screen is 2A, 1B and 1C

does anyone know how to do it ..



%x is a data vector with nonnegative integer components
%F=frequency(x) is the vector whose components are the
%frequencies with which each symbol in appear in x
%from most frequent to least frequent
%
function F = frequency(x)



x =[1,2,3,3,4,4,4,5,5,5]

k=max(x)+1;
for i=1:k;
j=find(x==i-1);
u(i)=length(j);
end
r=find(u>0);
v=u(r);
v=sort(v);
m=length(v);
for i=1:m;
F(i)=v(m-i+1);
hist(x);
title('Frequency of each symbol appear on a text')
xlabel('s')
ylabel('a')
end

 
Replies continue below

Recommended for you

Why do you want to do this?

xnuke

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
So why can't you sort the letters the same way?

TTFN
 
Use the unique command to sort the letters and find the unique values. Then use the find command to locate the letters. Then use the size command to get the number of letters. Then print the results

for example

x='zzzzjjccccdaaa'
ux=unique(x)
for iu=1:size(ux,2)
ifind=find(ux(iu)==x);
ic(iu)=size(ifind,2);
end

for iu=1:size(ux,2)
disp(sprintf('%c occurs %d times',ux(iu),ic(iu)));
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor