| Curve Fitting Toolbox™ | ![]() |
plot(fun)
plot(fun,xdata,ydata)
plot(fun,xdata,ydata,DataLineSpec)
plot(fun,FitLineSpec,xdata,ydata,DataLineSpec)
plot(fun,xdata,ydata,outliers)
plot(fun,xdata,ydata,outliers,OutlierLineSpec)
plot(...,ptype,...)
plot(...,ptype,level)
h = plot(...)
plot(fun) plots the cfit object fun over the domain of the current axes, if any. If there are no current axes, and fun is an output from the fit function, the plot is over the domain of the fitted data.
plot(fun,xdata,ydata) plots fun together with the predictor data xdata and the response data ydata.
plot(fun,xdata,ydata,DataLineSpec) plots the predictor and response data using the color, marker symbol, and line style specified by the DataLineSpec formatting string. DataLineSpec strings take the same values as LineSpec strings used by the MATLAB® plot function.
plot(fun,FitLineSpec,xdata,ydata,DataLineSpec) plots fun using the color, marker symbol, and line style specified by the FitLineSpec formatting string, and plots xdata and ydata using the color, marker symbol, and line style specified by the DataLineSpec formatting string. FitLineSpec and DataLineSpec strings take the same values as LineSpec strings used by the MATLAB plot function.
plot(fun,xdata,ydata,outliers) plots data indicated by outliers in a different color. outliers is a logical array the same size as xdata and ydata. outliers can be computed with the excludedata function.
plot(fun,xdata,ydata,outliers,OutlierLineSpec) plots outliers using the color, marker symbol, and line style specified by the OutlierLineSpec. OutlierLineSpec strings take the same values as LineSpec strings used by the MATLAB plot function.
plot(...,ptype,...) uses the plot type specified by ptype. Supported plot types are:
'fit' — Data and fit (default)
'predfunc' — Data and fit with prediction bounds for the fit
'predobs' — Data and fit with prediction bounds for new observations
'residuals' — Residuals
'stresiduals' — Standardized residuals (residuals divided by their standard deviation).
'deriv1' — First derivative of the fit
'deriv2' — Second derivative of the fit
'integral' — Integral of the fit
Plot types can be single or multiple, with multiple plot types specified as a cell array of strings. With a single plot type, plot draws to the current axes and can be used with commands like hold and subplot. With multiple plot types, plot creates subplots for each plot type.
plot(...,ptype,level) plots prediction intervals with a confidence level specified by level. level must be between 0 and 1. The default value of level is 0.95.
h = plot(...) returns a vector of handles to the plotted objects.
Create a baseline sinusoidal signal:
xdata = (0:0.1:2*pi)'; y0 = sin(xdata);
Add noise to the signal with non-constant variance:
% Response-dependent Gaussian noise gnoise = y0.*randn(size(y0)); % Salt-and-pepper noise spnoise = zeros(size(y0)); p = randperm(length(y0)); sppoints = p(1:round(length(p)/5)); spnoise(sppoints) = 5*sign(y0(sppoints)); ydata = y0 + gnoise + spnoise;
Fit the noisy data with a baseline sinusoidal model:
f = fittype('a*sin(b*x)');
fit1 = fit(xdata,ydata,f,'StartPoint',[1 1]);Identify "outliers" as points at a distance greater than 1.5 standard deviations from the baseline model, and refit the data with the outliers excluded:
fdata = feval(fit1,xdata);
I = abs(fdata - ydata) > 1.5*std(ydata);
outliers = excludedata(xdata,ydata,'indices',I);
fit2 = fit(xdata,ydata,f,'StartPoint',[1 1],...
'Exclude',outliers);Compare the effect of excluding the outliers with the effect of giving them lower bisquare weight in a robust fit:
fit3 = fit(xdata,ydata,f,'StartPoint',[1 1],'Robust','on');
Plot the data, the outliers, and the results of the fits:
plot(fit1,'r-',xdata,ydata,'k.',outliers,'m*') hold on plot(fit2,'c--') plot(fit3,'b:') xlim([0 2*pi])

Plot the residuals for the two fits considering outliers:
figure plot(fit2,xdata,ydata,'co','residuals') hold on plot(fit3,xdata,ydata,'bx','residuals')

cftool, excludedata, fit, differentiate, integrate
![]() | numcoeffs | predint | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |