필터 지우기
필터 지우기

Cannot add shaded confidence intervals?

조회 수: 10 (최근 30일)
nines
nines 2023년 1월 31일
답변: Star Strider 2023년 1월 31일
Hello all,
I have a graph with confidence intervals, where I want to make it so that the confidence intervals are shaded between both of them. I have the following code:
% 1) getting confidence intervals
[ci_groups, ci_pre, ci_post]=bootstrapping_function(matrix_mean, matrix_post_mean)
% 2) taking confidence intervals and multipling by size of matrix
ci_lower_pre = ci_pre(1)*ones(size(matrix_mean));
ci_higher_pre = ci_pre(2)*ones(size(matrix_mean));
% 3) making figure
figure;
plot(f_mr,matrix_mean, '-b'); hold on
% 4) fill the area between the confidence intervals
x = [f_mr, fliplr(f_mr)];
y = [matrix_mean + ci_higher_pre, fliplr(matrix_mean - ci_lower_pre)];
fill(x, y, 'r', 'FaceAlpha', 0.5, 'EdgeColor', 'none');
But when I use the code above I get the attached 'example' as my figure, where there is shading outside of the confidence intervals. Do you have any advice?
Thanks a ton

채택된 답변

Star Strider
Star Strider 2023년 1월 31일
We do not have your data. The fliplr function will not produce the desired result with column data.
I prefer to use the patch function —
f_mr = 1:10;
matrix_mean = rand(size(f_mr));
ci_higher_pre = rand(size(f_mr))/5;
ci_lower_pre = rand(size(f_mr))/5;
x = [f_mr, flip(f_mr)];
y = [matrix_mean + ci_higher_pre, flip(matrix_mean - ci_lower_pre)];
figure
patch(x, y, 'r', 'FaceAlpha', 0.5, 'EdgeColor', 'none') % Row Vectors
f_mr = f_mr(:);
matrix_mean = matrix_mean(:);
ci_higher_pre = ci_higher_pre(:);
ci_lower_pre = ci_lower_pre(:);
x = [f_mr; flip(f_mr)];
y = [matrix_mean + ci_higher_pre; flip(matrix_mean - ci_lower_pre)];
figure
patch(x, y, 'r', 'FaceAlpha', 0.5, 'EdgeColor', 'none') % Column Vectors
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by