×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

sorting english letter

sorting english letter

sorting english letter

(OP)
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

RE: sorting english letter

Why do you want to do this?

xnuke

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.

RE: sorting english letter

So why can't you sort the letters the same way?

TTFN

RE: sorting english letter

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources