boxplot labels from numbers and strings
Afficher commentaires plus anciens
Hello, How can I use both a vector of numbers and a string to label different boxplots in one graph? if a, b are vectors then something of this sort doesn't work boxplot([a,b],'labels',[1,'b'])
Thank you, Stefka
1 commentaire
Stefka
le 5 Nov 2015
Réponses (1)
_"[1,'b']"_ doesn't work outside of *boxplot*, either; you can't juxtapose character and numeric data in a vector. Use cell strings instead...
boxplot([a b],'labels',{'1';'b'})
Or more generically, num2str(v) if v is a value returns the character representation rather than hardcoding it.
ADDENDUM
N=10; % a number of points to illustrate...
a=randn(5,N); % rand data to plot for N observations...
boxplot(a,num2str([1:N].','Obs%2d');
The only "trick" above is to be sure to orient the numeric vector as a column; that's the hint to num2str to put each element on a separate row; otherwise the all get run together on a single line.
Any other of a multitude of ways can be used to generate the label strings as long as end up with either a column character array or a cellstr array.
Catégories
En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!