Search code examples
matlabhistogramcell

Count strings occurrences and plot histogram


Is there any straightforward way to create a histogram from a cell array like the one below? The spacing between the consecutive bars should be exactly the same and the labels of the x-axis should be the corresponding names of the variables below in a vertical orientation.

'w464'
'w462'
'w461'
'w464'
'w461'
'w463'
'w466'
'w461'

Solution

  • 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})