필터 지우기
필터 지우기

boxplot labels from numbers and strings

조회 수: 5 (최근 30일)
Stefka
Stefka 2015년 11월 5일
편집: dpb 2015년 11월 5일
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
Stefka
Stefka 2015년 11월 5일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
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.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by