plotAverage adds an average line into plotted data.
By default, plotAverage
- calculates the average along y (for given or estimated points along x)
- plots errorbars with the standard error of the mean
- discards outliers to calculate the robust average
- plots the average line into the data's axes (as opposed to a new figure)
All these options can be changed.
plotAverage returns the handles to the average line and the error bars as well as the x and y data of the line.
Hi, could you please give one example to use this code? Thank you so much!
This looks very useful. I have ten blue lines and I want to create an average of the 10 over the top, but when I try and use plotAverage it produces another graph in a new window with a range of different coloured lines on. Is there a way to just get the average line over the top of the original?
In this case, I suggest you pass the data used to create the line groups as input to plotAverage.
If you do not have access to the data anymore, but each subgroup has its own color (or e.g. its own tag), you can use "findobj" to gather the line handles and extract x and y data. For example, to plot an average for the blue group:
blueH = findobj(gcf,'color','b');
xData = get(blueH,'xData');
yData = get(blueH,'yData');
xyData = [xData,yData]';
This is great and really helpful!
Quick question is that what would need to do if I have four subgroups of data in one plot, and each subgroup contains multiples lines that need to be averaged.
Here's an example:
x = 1:0.1:10;
cmap = jet(10);
% plot some lines
% add average, set robust-option to 0
is there any example on how to use the file plotAverage?