Count strings occurrences and plot histogram

后端 未结 4 474
陌清茗
陌清茗 2021-01-18 05:09

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 labe

4条回答
  •  暖寄归人
    2021-01-18 05:24

    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)
    

提交回复
热议问题