Products & Services Solutions Academia Support User Community Company

Learn more about Curve Fitting Toolbox   

plot - Plot cfit or sfit object

Syntax

plot(sfit)
plot(sfit, [x, y], z)
plot(sfit, [x, y], z, 'Exclude', ExcludeData)
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,xdata,ydata)
plot(cfit,xdata,ydata,DataLineSpec)
plot(cfit,FitLineSpec,xdata,ydata,DataLineSpec)
plot(cfit,xdata,ydata,outliers)
plot(cfit,xdata,ydata,outliers,OutlierLineSpec)
plot(...,ptype,...)
plot(...,ptype,level)
h = plot(...)

Description

For surfaces:

For curves:

For both curves and surfaces:

Example

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')

See Also

cftool, excludedata, fit, differentiate, integrate

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS