How do I plot confidence intervals in MATLAB?

前端 未结 3 1905
半阙折子戏
半阙折子戏 2021-01-14 17:36

I want to plot some confidence interval graphs in MATLAB but I don\'t have any idea at all how to do it. I have the data in a .xls file.

Can someone give me a hint,

3条回答
  •  感动是毒
    2021-01-14 17:48

    After reading numerous threads, here's my attempt.

    % Get some random data
    x       = linspace(0.3, pi-0.3, 10);
    Data    = sin(x) + randn(1, 10)/10;
    Data_sd = 0.1+randn(1,10)/30;
    
    % prepare it for the fill function
    x_ax    = 1:10;
    X_plot  = [x_ax, fliplr(x_ax)];
    Y_plot  = [Data-1.96.*Data_sd, fliplr(Data+1.96.*Data_sd)];
    
    % plot a line + confidence bands
    hold on 
    plot(x_ax, Data, 'blue', 'LineWidth', 1.2)
    fill(X_plot, Y_plot , 1,....
            'facecolor','blue', ...
            'edgecolor','none', ...
            'facealpha', 0.3);
    hold off 
    

    Mostly based on this question: Plotting with transparency

提交回复
热议问题