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.
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.
x = 1:0.1:10;
cmap = jet(10);
% plot some lines
% add average, set robust-option to 0