我有以下示例代码:
Node
我可以在代码中添加什么来显示方框图中每个向量的平均值而不是中位数(这是默认的Matlab),我知道如何为一个向量执行此操作但是如果我们有多个箱图,我需要一些帮助怎么做。
有什么建议吗?
答案 0 :(得分:0)
尝试删除中线,然后绘制相关方法 :
A = [16 20 15 17 22 19 17]';
B = [22 15 16 16 16 18]';
C = [23 9 15 18 13 27 17 14 16 15 21 19 17]';
% Calculate means
meanOfA = mean(A);
meanOfB = mean(B);
meanOfC = mean(C);
group = [ ones(size(A));
2 * ones(size(B));
3;
4 * ones(size(C))
];
figure;
boxplot([A; B; NaN; C],group);
set(gca,'XTickLabel',{'A','B','','C'});
% Find handle for median line and set visibility off
h = findobj(gca,'Tag','Median');
set(h,'Visible','off');
%plot means as black asterisks.
hold on
plot(1,meanOfA, 'k*')
plot(2,meanOfB, 'k*')
plot(4,meanOfC, 'k*')