Home plot categorization of strings, matlab
Reply: 2

plot categorization of strings, matlab

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:


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_ Reply to 2015-05-25 21:20:53Z

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  ];

% scatter(1:length(c), c) % use this for a scatter plot
set(gca, 'xticklabel', v)
user1543042 Reply to 2015-05-25 23:13:38Z

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.

ax = gca;
ax.XTick = 1:length(c);
ax.YTick = 0:max(c);
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.375896 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO