Code covered by the BSD License  

Highlights from
plotdata, version 2

Be the first to rate this file! 6 Downloads (last 30 days) File Size: 2.81 KB File ID: #33191
image thumbnail

plotdata, version 2

by Tom O'Haver

 

09 Oct 2011 (Updated 17 Oct 2011)

A simple data plotting function, useful for plotting x,y data and polynomial fitting.

| Watch this File

File Information
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

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
11 Oct 2011 Tom O'Haver

This function replaces and extends my earlier "plotfit" function, whose name conflicted with the name of a Matlab-supplied function.

Please login to add a comment or rating.
Updates
17 Oct 2011

Version 2 now plots and fits multiple dependent variables in a matrix.

Tag Activity for this File
Tag Applied By Date/Time
signal processing Tom O'Haver 10 Oct 2011 11:01:51
data import Tom O'Haver 10 Oct 2011 11:01:51

Contact us at files@mathworks.com