Adding variance as error bars on line plot
조회 수: 15 (최근 30일)
이전 댓글 표시
I am plotting several datasets on a single figure where each point on the line is defined as the average of different runs of the same experiment.
It is simple enough to plot the lines of each datasets but is it also possible to include the variance either side of the average calculated at each data point on the lines?
Example: y1(1) = 1; y1(2) = 2; y1(3) = 3; %similar for y2 & y3 y = [mean(y1),mean(y2),mean(y3)]; x = [1,2,3]; plot(x,y); %How to add variance as shown as an error bar at y1, y2, y3....
댓글 수: 0
채택된 답변
Star Strider
2018년 8월 29일
편집: Star Strider
2018년 8월 29일
There are probably several ways to do the plot, using the errorbar (link) function being the easiest.
See the links in those documentation pages for related functions.
EDIT —
A more useful metric than the variance is the standard error of the mean (SEM), calculated as the standard deviation divided by the square root of the number of observations. You can convert this to confidence intervals by multiplying it by the inverse value of the t-distribution with a given probability and degrees-of-freedon, given by the Statistics and Machine Learning Toolbox tinv (link) function.
Example —
x = 1:10; % Create Data
y1 = rand(1,10); % Create Data
y2 = rand(1,10); % Create Data
y3 = rand(1,10); % Create Data
ym = [y1; y2; y3];
N = size(ym,1);
y = mean(ym);
SEM = std(ym) / sqrt(N); % Standard Error Of The Mean
CI95 = SEM * tinv(0.975, N-1); % 95% Confidence Intervals
figure
errorbar(x, y, CI95)
grid
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!