Plot cfit
or sfit
object
plot(sfit)
plot(sfit, [x, y], z)
plot(sfit, [x, y], z, 'Exclude', outliers)
H = plot(sfit, ..., 'Style', Style)
H = plot(sfit, ..., 'Level', Level)
H = plot(sfit, ..., 'XLim', XLIM)
H
= plot(sfit, ..., 'YLim', YLIM)
H = plot(sfit, ...)
H = plot(sfit, ..., 'Parent', HAXES )
plot(cfit)
plot(cfit,x,y)
plot(cfit,x,y,DataLineSpec)
plot(cfit,FitLineSpec,x,y,DataLineSpec)
plot(cfit,x,y,outliers)
plot(cfit,x,y,outliers,OutlierLineSpec)
plot(...,ptype,...)
plot(...,ptype,level)
h = plot(...)
For surfaces:
plot(sfit)
plots the
sfit
object over the range of the current axes,
if any, or otherwise over the range stored in the fit.
plot(sfit, [x, y], z)
plots z versus x and y and
plots sfit
over the range of x and y.
plot(sfit, [x, y], z, 'Exclude', outliers)
plots
the excluded data in a different color. outliers
can
be an expression describing a logical vector, e.g., x >
10
, a vector of integers indexing the points you want to
exclude, e.g., [1 10 25]
, or a logical array where
true
represents an outlier. You can create the
array with excludedata
.
H = plot(sfit, ..., 'Style', Style)
selects which
way to plot the surface fit object sfit
.
Style
may be any of the following character vectors
'Surface'
Plot the fit object as a
surface (default)
'PredFunc'
Surface with prediction
bounds for function
'PredObs'
Surface with prediction
bounds for new observation
'Residuals'
Plot the residuals (fit is
the plane Z=0)
'Contour'
Make a contour plot of the
surface
H = plot(sfit, ..., 'Level', Level)
sets the
confidence level to be used in the plot. Level
is a
positive value less than 1, and has a default of 0.95 (for 95%
confidence). This option only applies to the
'PredFunc'
and 'PredObs'
plot
styles.
H = plot(sfit, ..., 'XLim', XLIM)
and
H
= plot(sfit, ..., 'YLim', YLIM)
sets the limits
of the axes used for the plot. By default the axes limits are taken from
the data, XY
. If no data is given, then the limits
are taken from the surface fit object, sfit
.
H = plot(sfit, ...)
returns a vector of handles
of the plotted objects.
H = plot(sfit, ..., 'Parent', HAXES )
plots the
fit object sfit
in the axes with handle HAXES rather
than the current axes. The range is taken from these axes rather than
from the fit or the data.
For curves:
plot(cfit)
plots the
cfit
object 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(cfit,x,y)
plots
cfit
together with the predictor data
x
and the response data
y
.
plot(cfit,x,y,DataLineSpec)
plots the predictor and response data using the color, marker symbol,
and line style specified by the DataLineSpec
formatting character vector. DataLineSpec
character
vectors take the same values as LineSpec
character
vectors used by the MATLAB®
plot
function.
plot(cfit,FitLineSpec,x,y,DataLineSpec)
plots fun
using the color, marker symbol, and line
style specified by the FitLineSpec
formatting
character vector, and plots x
and
y
using the color, marker symbol, and line style
specified by the DataLineSpec
formatting character
vector. FitLineSpec
and
DataLineSpec
character vectors take the same
values as LineSpec
character
vectors used by the MATLAB
plot
function.
plot(cfit,x,y,outliers)
plots
data indicated by outliers
in a different color.
outliers
can be an expression describing a
logical vector, e.g., x > 10
, a vector of integers
indexing the points you want to exclude, e.g., [1 10
25]
, or a logical array where true
represents an outlier. You can create the array with excludedata
.
plot(cfit,x,y,outliers,OutlierLineSpec)
plots outliers
using the color, marker symbol, and
line style specified by the OutlierLineSpec
.
OutlierLineSpec
character vectors take the same
values as LineSpec
character
vectors 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(...,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
.
For both curves and surfaces:
Plot types can be single or multiple, with multiple plot types
specified as a cell array of character vectors. 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.
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')
Load data and fit a Gaussian, excluding some data with an expression, then plot the fit, data and the excluded points.
[x, y] = titanium; f1 = fit(x',y','gauss2', 'Exclude', x<800); plot(f1,x,y,x<800)
For more examples excluding data and plotting fits, see fit
.