Cannot add shaded confidence intervals?

8 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by