Home plot categorization of strings, matlab

# plot categorization of strings, matlab

user44874
1#
user44874 Published in 2015-05-25 20:42:41Z
 Edit: while the solution suggested works this format is problematic when I have many long strings, any suggestions? Lets say I have categorized a vector of M stings into N groups. Meaning each of the M strings is assigned a number between 1 to N indicating the category the string belongs into. For example if M=6 and N=3 I might have: v = [ 'a' ; 'b' ; 'c' ; 'd' ; 'e' ; 'f' ] c = [ 1 ; 2 ; 1 ; 1 ' 3 ; 2 ]  which indicates that a, c and d were all categorized to group "1". "e" was categorized to group 3. I want to somehow plot - using Matlab - this categorization. I am trying something along the lines of: plot(v,'b--o') set(gca,'xticklabel',c.')  but I need the plot to look more like a scatter, sadly it seems scatter does not work with strings. Any suggestions? Plus, the vector of strings might get very long, anyone knows how to make the plot scrollable?
ulima2_
2#
 The following gets you a barchart with your names as x-axis labels. Uncomment the other line for a scatterplot. In general, such a visualisation is probably not the right format for extremely many words (very high M). v = [ 'a' ; 'b' ; 'c' ; 'd' ; 'e' ; 'f' ]; c = [ 1 ; 2 ; 1 ; 1 ; 3 ; 2 ]; bar(c) % scatter(1:length(c), c) % use this for a scatter plot set(gca, 'xticklabel', v) 
 bar is usually slow. You can get a similar result more quickly and without Matlab binning things funnily by using plot. Edit: I think you wanted the strings on the y axis. plot(c,'bo') ax = gca; ax.XTick = 1:length(c); ax.YTick = 0:max(c); set(ax,'xticklabel',v) view(-90,90)