MATLAB: How to plot mean scores of dataset with different number of variables

plotting

I have a matrix of 2922 samples with scores for 23 components (2922×23) double.
I want to plot the mean value of the first component for data points 1-320, 321-655, 656-1001, 1002-1338, 1339-1684, 1685-2027, 2028-2348, 2349,2581 and 2582-2922 including an error bar of +/-1 standard deviation for each group. The components are not numerical values.
What would be the simplest way to do this for each component? The number of data points within each set will never be the same. Ideally I would like to group the 9 "sets" into 2 groups of 4 and 5 which have different coloured plots.

Best Answer

% Make up some pretend data
data = rand(2922,23);
% 1-320, 321-655, 656-1001, 1002-1338, 1339-1684, 1685-2027, 2028-2348, 2349,2581 and 2582-2922
edge = [0 320 655 1001 1338 1684 2027 2348 2581 2922];
% Find the number of sections
numberSections = numel(edge)-1;
% Preallocate memory for mean and std dev
sectionMean = nan(numberSections,1);
sectionStd = nan(numberSections,1);
% Calculate the stats for each section
for ne = 1:numberSections
indexToSection = edge(ne)+1:edge(ne+1);
sectionMean(ne) = mean(data(indexToSection,1));
sectionStd(ne) = std(data(indexToSection,1));
end
% Plot
figure
errorbar(sectionMean,sectionStd)
Related Question