Perhaps this example was too simple, but if you have to change the labels you have to type everything again. Suppose you have 8 boxplots in a graph, and you assign labels corresponding to the number of the column of the matrix A by typing boxplot(A(:,1:7),'labels', {'1','2',...'6','emp'}). Now you need to change the boxplots to A(:,5:10) and change the labels to {'5','6'',...'10'}. Is there an easier way than just type again everything? How would num2str(v) work in this respect. I tried several versions with set(gca,'XTickLabel',..) but it doesn't work.
boxplot labels from numbers and strings
5 次查看(过去 30 天)
显示 更早的评论
回答(1 个)
dpb
2015-11-5
编辑:dpb
2015-11-5
_"[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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!