필터 지우기
필터 지우기

How to plot different grouped boxplots in a shared x axis with different dimensions that are inconsistent?

조회 수: 2 (최근 30일)
Hi! I want to ask how to plot this 3 different grouped boxplots in a shared x-axis? because i plan to see the differences between them and add another secondary label to it. I want to make something like in the picture (attached), but I don't know how to make it work because i keep on having an error that says "dimensions of arrays being concatenated are not consistent".
close all; clear all; clc;
%--------------------------------------------------------------------------
% Data from 1mm
a = load ("All-1mm.txt");
b = load ("Origin-1mm.txt");
% Data from 2mm
c = load ("All-2mm.txt");
d = load ("Origin-2mm.txt");
% Data from 3mm
e = load ("All-3mm.txt");
f = load ("Origin-3mm.txt");
%--------------------------------------------------------------------------
figure
boxplot (a, b);
ylabel ("Displacement (m)");
title('1 mm Displacement');
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = 'none'; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {'X', 'Y', 'Z', 'Combined'}; % Assign secondary labels
figure
boxplot (c, d);
ylabel ("Displacement (m)");
title('2 mm Displacement');
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = 'none'; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {'X', 'Y', 'Z', 'Combined'}; % Assign secondary labels
figure
boxplot (e, f);
ylabel ("Displacement (m)");
title('3 mm Displacement');
% Set the x-axis tick labels
ax = gca;
ax.XAxis.TickLabelInterpreter = 'none'; % To display labels without interpreting LaTeX or special characters
ax.XAxis.TickLabels = {'X', 'Y', 'Z', 'Combined'}; % Assign secondary labels

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 5월 9일
Here's a quick approach
cats = {'X', 'Y', 'Z', 'Combined'};
% Data from 1mm
a = load ("All-1mm.txt");
b = load ("Origin-1mm.txt");
A = [a,b];
g1 = repmat({'1 mm'},length(a),1);
% Data from 2mm
c = load ("All-2mm.txt");
d = load ("Origin-2mm.txt");
C = [c,d];
g2 = repmat({'2 mm'},length(c),1);
% Data from 3mm
e = load ("All-3mm.txt");
f = load ("Origin-3mm.txt");
E = [e,f];
g3 = repmat({'3 mm'},length(e),1);
data = [A;C;E];
G2 = cats(data(:,2));
G1 = [g1;g2;g3];
%--------------------------------------------------------------------------
figure
boxplot(data(:,1),{G1,G2},'FactorGap',[30])
ylabel ("Displacement (m)");
title('Displacement');

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by