www.gusucode.com > curvefit 案例源码程序 matlab代码 > curvefit/PredictionIntervalsExample.m

    %% Prediction Intervals
% This example shows how to compute and plot prediction intervals at the command line.
%% 
% Generate data with an exponential trend:

% Copyright 2015 The MathWorks, Inc.

x = (0:0.2:5)';
y = 2*exp(-0.2*x) + 0.5*randn(size(x));
%% 
% Fit the data using a single-term exponential:
fitresult = fit(x,y,'exp1');
%% 
% Compute prediction intervals:
p11 = predint(fitresult,x,0.95,'observation','off');
p12 = predint(fitresult,x,0.95,'observation','on');
p21 = predint(fitresult,x,0.95,'functional','off');
p22 = predint(fitresult,x,0.95,'functional','on');
%% 
% Plot the data, fit, and prediction intervals:
subplot(2,2,1)
plot(fitresult,x,y), hold on, plot(x,p11,'m--'), xlim([0 5])
title('Nonsimultaneous observation bounds','Color','m')
subplot(2,2,2)
plot(fitresult,x,y), hold on, plot(x,p12,'m--'), xlim([0 5])
title('Simultaneous observation bounds','Color','m')
subplot(2,2,3)
plot(fitresult,x,y), hold on, plot(x,p21,'m--'), xlim([0 5])
title('Nonsimultaneous functional bounds','Color','m')
subplot(2,2,4)
plot(fitresult,x,y), hold on, plot(x,p22,'m--'), xlim([0 5])
title('Simultaneous functional bounds','Color','m')