## plotit(xi,yi,polyor​der,datastyle,fitst​yle)

version 6.0.0.0 (11.5 KB) by
Simple function for plotting and fitting x,y data to polynomials, with error estimation.

Updated 24 Oct 2015

function [coef,RSquared,StdDevs,BootResults]=plotit(xi,yi,polyorder)
plotit accepts data in the form of a single vector, a pair of vectors,
"x" and "y", or a 2xn or nx2 matrix with x in first row or column. If the
input argument "polyorder" is supplied, it fits the data to a polynomial
of order "polyorder", plots the data in red dots and the fit as a blue
line, and displays the fit coefficients, their estimated standard deviations, and R-squared in the upper left
corner of the graph. Polyorder=1 for straight line, =2 for quadratic
(parabola) etc. If the 4th output argument (BootResults) is supplied,
computes coefficient error estimates by the bootstrap method and returns
the results in the matrix "BootResults" (of size 5 x polyorder+1). You
can change the number of bootstrap samples in line 48.
Tom O'Haver, In version 6 the syntax is [coef, RSquared, StdDevs] = plotit(x,y) or plotit(x,y,n) or optionally plotit(x,y,n, datastyle, fitstyle), where datastyle and fitstyle are optional strings specifying the line and symbol style and color, in standard Matlab convention.
Examples:
x=[1 2 3 4 5];y=[0 2 3 3 5];
plotit(y); % plot y only vs index number, no fit.
plotit(x,y); % plot x vs y only, data in separate vectors
plotit([x;y]); % plot data only, data in matrix with x in first row
plotit([x;y]'); % plot data only, data in matrix with x in first column
plotit(y,2); % plot y vs index and fit to second order polynomial
plotit(x,y,3); % plot x vs y and fit to third order polynomial
plotit([x;y],3); % plot and fit data in matrix
[coef, RSquared]=plotit([x;y],2) % return fit coefficients and r-squared
[coef,RSquared,STD]=plotit([x;y],2) Returns vector standard deviations
of coefficients as 'STD'. (STD./coef computes relative standard deviation)
[coef, RSquared,,StdDevs,BootResults]=plotit(x,y,polyorder) % computes
coefficient error estimates by the bootstrap method and returns the
results in the matrix "BootResults"

### Cite As

Tom O'Haver (2021). plotit(xi,yi,polyorder,datastyle,fitstyle) (https://www.mathworks.com/matlabcentral/fileexchange/48679-plotit-xi-yi-polyorder-datastyle-fitstyle), MATLAB Central File Exchange. Retrieved .

##### MATLAB Release Compatibility
Created with R2009b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!