【发布时间】:2021-05-02 20:45:49
【问题描述】:
下面是我用来在一个图中绘制多个箱线图的 MATLAB 代码。但是,这仅适用于数据长度相等的情况(本例中为 n1,n2,n3,n4,n5,n6 =10)。如何更改它以使其适用于长度不等的数据集?例如:n1=10,n2=10,n3=15,n4=15,n5=5,n6=5?
clc
clear
n1=10;n2=10;n3=10;n4=10;n5=10;n6=10;
x=[rand(1,n1) rand(1,n2) rand(1,n3) rand(1,n4) rand(1,n5) rand(1,n6)];
n=10 ; xx=([1:6])'; % example
r=repmat(xx,1,n)';
g=r(:)';
positions = [1 2 3 4 5 6 ];
h=boxplot(x,g, 'positions', positions);
set(h,'linewidth',2)
set(gca,'xtick',[mean(positions(1:2)) mean(positions(3:4)) mean(positions(5:6)) ])
set(gca,'xticklabel',{'exp1','exp2','exp3'},'Fontsize',28)
color = ['c', 'y', 'c', 'y','c', 'y'];
h = findobj(gca,'Tag','Box');
for j=1:length(h)
patch(get(h(j),'XData'),get(h(j),'YData'),color(j),'FaceAlpha',.5);
end
【问题讨论】:
-
用
hold on循环调用boxplot -
你能举个例子吗?它对我不起作用。
-
你尝试了什么,什么没用?
-
我不确定如何对不平衡数据使用保持循环。你能帮忙吗?
-
不存在“保持循环”
标签: matlab matlab-figure boxplot