Search code examples
matlabmatlab-figure

MATLAB - Stuck on changing x axis for boxplot


I've just spent the last hour trying to change the X axis labels for a boxplot in MATLAB. It has sp,ething to do with the way I'm storing and then disaplying the dsata, but I can't figure out the Issue. Here is the chart I'm producing:

enter image description here

The visual is fine, but on the X axis of the left boxplot I want to change the labels from "1 2" to a label of my choosing. The issue I am having is that I can never get the axis to change at all, or I can only get label "1" to change. I suspect this has something to do with the way I'm storing the data:

box_steel_60mm = zeros(100, 2);
box_nometal = zeros(100, 2);
plot_boxplot = zeros(100, 4);
plot_boxplot_steel_60mm = zeros(100, 2);

for n = 1:100
box_steel_60mm(n, 1) = mean(steel_60mm{n});
box_steel_60mm(n, 2) = median(steel_60mm{n});
box_nometal(n, 1) = mean(nometal{n});
box_nometal(n, 2) = median(nometal{n});
end
tiledlayout(1,2);
nexttile
mean_box(:,1) = mean_box_nometal;
med_box(:,1)= med_box_nometal;
mean_box(:,2) = mean_box_steel_60mm;
med_box(:,2) = med_box_steel_60mm;
hold on;

boxchart(box_nometal(:,1:2));
boxchart(box_steel_60mm(:,1:2));
xticklabels('Mean/Median No Metal','Mean/Median 60mm Steel')
%legend('Mean/Median No Metal','Mean/Median 60mm Steel');
nexttile
plot(nometal{n});
hold on
plot(steel_60mm{n});
legend('No Metal Curve','60mm Steel Curve');

Solution

  • Try

    xticklabels({'Mean/Median No Metal','Mean/Median 60mm Steel'})
    

    Source