Count strings occurrences and plot histogram
I would like to know a better way, as well. Fwiw, I have used countmember in a roundabout way to plot data like this. I.E. if the data you posted was named A
>> B={sort(unique(A)) countmember(sort(unique(A)),A)};
>> bar(B{2});
>> set(gca,'XTickLabel',B{1})
If you have access to the statistics toolbox, grp2idx
is very useful:
%# sorting is only necessary if the output should be sorted as well
[idx,label] = grp2idx(sort(A))
hist(idx,unique(idx));
set(gca,'xTickLabel',label)
A solution that only uses built-in functions
[u,~,n] = unique(A(:));
B = accumarray(n, 1, [], @sum);
bar(B)
set(gca,'XTickLabel',u)