MATLAB:不同长度向量的组合箱线图
MATLAB: combination boxplot of different length vectors
如果大小不同,我有三个向量(86x1 双精度)、(61x1 双精度)和(10x1 双精度)。
我试试:
figure
boxplot([x1,x2,x3])
但得到"error using horzcat, dimensions of matrices being concatenated are not consistent"。
我试过转置这些向量,但它看起来像是将它们组合成一组并为此绘制了一个箱线图。即如果我有
boxplot([x1,x2,x3],'Labels','thing1','thing2','thing3')
我得到:
“来自非结构数组对象的结构内容引用。
使用箱线图时出错>assignUserLabels(第 1688 行)
必须有与组或数量相同的标签
X 中的元素数。
由于x1
、x2
和x3
大小不同,不能将它们转换成一个大矩阵。并且您不能使用 boxplot(x)
语法,其中 x 是矩阵。
在这种情况下,您需要一个分组变量:
boxplot(x,g) creates a box plot using one or more grouping variables contained in g. boxplot produces a separate box for each set of x values that share the same g value or values.
文档来自https://www.mathworks.com/help/stats/boxplot.html
这是一个如何根据给定输入创建分组变量的示例。
g1 = ones(size(x1)) * 1;
g2 = ones(size(x2)) * 2;
g3 = ones(size(x3)) * 3;
figure()
boxplot([x1; x2; x3], [g1; g2; g3], 'Labels', {'thing1', 'thing2', 'thing3'})
如果大小不同,我有三个向量(86x1 双精度)、(61x1 双精度)和(10x1 双精度)。
我试试:
figure
boxplot([x1,x2,x3])
但得到"error using horzcat, dimensions of matrices being concatenated are not consistent"。
我试过转置这些向量,但它看起来像是将它们组合成一组并为此绘制了一个箱线图。即如果我有
boxplot([x1,x2,x3],'Labels','thing1','thing2','thing3')
我得到:
“来自非结构数组对象的结构内容引用。
使用箱线图时出错>assignUserLabels(第 1688 行) 必须有与组或数量相同的标签 X 中的元素数。
由于x1
、x2
和x3
大小不同,不能将它们转换成一个大矩阵。并且您不能使用 boxplot(x)
语法,其中 x 是矩阵。
在这种情况下,您需要一个分组变量:
boxplot(x,g) creates a box plot using one or more grouping variables contained in g. boxplot produces a separate box for each set of x values that share the same g value or values.
文档来自https://www.mathworks.com/help/stats/boxplot.html
这是一个如何根据给定输入创建分组变量的示例。
g1 = ones(size(x1)) * 1;
g2 = ones(size(x2)) * 2;
g3 = ones(size(x3)) * 3;
figure()
boxplot([x1; x2; x3], [g1; g2; g3], 'Labels', {'thing1', 'thing2', 'thing3'})