how can i create a array of letters from a sentence
Show older comments
"Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes. The ones who see things differently. They're not fond of rules. And they have no respect for the status quo. You can quote them, disagree with them, glorify or vilify them. About the only thing you can't do is ignore them. Because they change things. They push the human race forward. And while some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they can change the world, are the ones who do."
for the above mentioned sentence i would like to obtain the shanon fano code. i tried to count the different entries of charecters.
%Shanon-Fano encoding
src=fopen('ShanonFanotext.txt');%text source
scan=fread(src);%source analysis
symb=unique(scan);%Obtainig info about distinguished charecters
span=length(symb);%No. of symbols used to construct the sentence.
%Obtaining probabilities of each symbols as per the occurences in source
for n=1:length(s3)
d(n,1)=length(find(scan==symb(n)))%frequencies of each symbol
end
Here the fread command just gives the binary output.
i want to carry out for alphabet letters as such a symbol.
5 Comments
per isakson
on 5 Apr 2020
Edited: per isakson
on 5 Apr 2020
Use fileread() instead of fread()
"I tried to count the different entries of charecters." Try this
%%
txt = fileread('ShanonFanotext.txt');
%%
num = double( txt ); % "ascii" numbers
[N,edges] = histcounts( num, min(num):max(num) );
bar( edges, [N,nan] )
There is one hundred spaces in your sample text.
Saibala Sundram
on 5 Apr 2020
per isakson
on 5 Apr 2020
"In the x axis is that asci values?" Yes
Saibala Sundram
on 5 Apr 2020
per isakson
on 5 Apr 2020
Edited: per isakson
on 5 Apr 2020
Just guessing has its limits:)
I found this code
% Change the labels for the tick marks on the x-axis
irisSpecies = {'Setosa', 'Virginica', 'Versicolor'};
set(gca, 'XTick', 1:3, 'XTickLabel', irisSpecies)
in "Errorbar Plot" at MATLAB Plot Gallery
Accepted Answer
More Answers (0)
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
