I have two Column in excel. I import it to matlab and I create boxplot for them.
I use boxplot
function:
boxplot(BasePay,JobTitle)
now I want create boxplot for some value of JobTitle
for example JobTitle1
and JobTitle2
. These is my data:
Job Title Base Pay
JobTitle1 486927.08
JobTitle1 461785.8
JobTitle2 523782.43
JobTitle4 388849.77
JobTitle2 380452.08
JobTitle1 450053.76
JobTitle2 546416.52
JobTitle3 384411.2
JobTitle4 353637.71
JobTitle4 311209.74
JobTitle3 355242.48
JobTitle2 359855.85
答案 0 :(得分:1)
我不确定你如何保存这些数据,但假设JobTitle
的单元格数组和BasePay
的向量数据,你可以这样写:
boxplot(BasePay(strcmp(JobTitle,'JobTitle1') | strcmp(JobTitle,'JobTitle2')));
如果你想查看几个箱图,你最好这样做:
grp = strcmp(JobTitle,'JobTitle1') | strcmp(JobTitle,'JobTitle2');
boxplot(BasePay,grp);
bp = gca;
bp.XTickLabel = {'all other','JobTitle1&2'};
或者,如果您只想仅绘制JobTitle1
和JobTitle2
,则可以单独编写:
boxplot(BasePay(grp),JobTitle(grp));
使用上面的grp
变量,无需设置标签。