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

조회 수: 3 (최근 30일)
I have a matrix of 2922 samples with scores for 23 components (2922x23) 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.

채택된 답변

the cyclist
the cyclist 2019년 11월 15일
% 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)
  댓글 수: 8
the cyclist
the cyclist 2019년 11월 20일
편집: the cyclist 2019년 11월 20일
You definitely do not want just
std(ne)
because ne is a scalar, and std(ne) is going to be zero. It is in no way related to the standard deviation of your data.
This addition to my code above works for me:
% 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);
sectionStdErr = 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));
sectionStdErr(ne) = sectionStd(ne)/sqrt(numel(data(indexToSection,1)));
end
% Plot
figure
errorbar(sectionMean,sectionStdErr)
The modification is that I added the calculation of the standard error, and plotted it instead of the standard deviation.
Kirsty Milligan
Kirsty Milligan 2019년 11월 20일
Thank you so much! Works perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by