Search code examples
matlabanovaxticks

Matlab Anova changing "Test number" on x axis


Using the built in Matlab function to run ANOVA on some data. I have groups of tests that I want to look at independently of the other tests, i.e. I want to run ANOVA on tests 1, 2 & 3, then 4, 5 & 6 and so on but when I look at 4, 5 & 6 the built in function always labels the x axis "1,2,3" as shown below.

How do I change the labels on the x axis to match the test number? (In the image below the x-axis reads 1,2,3 and not 4,5,6!) I have tried using "xticks" but that seems to just delete the autogenerated numbers and not add the numbers I want.

TIA

    %Get data in
x = csvread('data.csv');

%single factor anova
[p,tbl,stats] = anova1(x(1:end,4:6));
title('Anova Tests 4, 5 & 6');
xlabel('Test Number');
ylabel('Load (N)');
ylim([0 50]);

enter image description here

Code/help for anova1 function: https://www.mathworks.com/help/stats/one-way-anova.html


Solution

  • The documentation states:

    You can get some graphical assurance that the means are different by looking at the box plots. [...] For more information on this display, see boxplot.

    Like most plot types in MATLAB, you can change the axis labels of a boxplot with xticklabels(). In this case:

    xticklabels( [4 5 6] );
    

    For robustness you could do

    idx = 4:6;
    [p,tbl,stats] = anova1(x(1:end,idx));
    xticklabels( idx );