| Description |
function [coef, RSquared]=plotdata(xi,yi,polyorder)
A simple data plotting function, useful for inspecting x,y data.
The function accepts data in the form of a single vector, a pair of
vectors "x" and "y", or a single NxM or MxN matrix with the
independent variable (x) in first row or column (whichever is longer)
and dependent variables y1, y2... in the remaining rows or
columns, and plots x vs all y's. If only a single vector is supplied,
plots it vs its index. If yi is a matrix, all the rows or columns are
plotted. If yi is a vector and the input argument "polyorder" is
supplied, a polynomial of order "polyorder" is fit to the data, plotted
as a red line vs the data as blue dots, showing the fit coefficients
and R-squared in the upper left corner of the graph.
Polyorder=1 for straight line, =2 for quadratic (parabola) etc.
If yi is a matrix and the input argument "polyorder" is supplied, fits
row or column vs xi, plots data as points and the fits as lines, and
returns a matrix of coefficients and a vector of R-squared values (does
not label graph with fit coefficients and R-squared in that case). If a
matrix M does not have an independent variable in the first row or column,
type plotdata(1:length(M),M) or plotdata(1:length(M),M, polyorder).
Tom O'Haver, 2011. Version 2, October 2011, fits multiple signals in y matrix
Examples:
x=[1 2 3 4 5];y=[ 0 2 3 2 0];
plotdata(y); % plot y only vs index number, no fit.
plotdata(x,y); % plot x vs y only, data in separate vectors
plotdata([x;y]); % plot data only, data in matrix with x in first row
plotdata([x;y]'); % plot data only, data in matrix with x in first column
plotdata(y,2); % plot y vs index and fit to second order polynomial
plotdata(x,y,3); % plot x vs y and fit to third order polynomial
plotdata([x;y],3); % plot and fit data in matrix
[coef, RSquared]=plotdata([x;y],2) % return fit coefficients and r-squared
[coef, RSquared]=plotdata([x;y1;y1;y3],2) % fit each y vs x
|