Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Single Trendline for multiple datasets
Replies: 2   Last Post: Jan 23, 2013 3:55 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,892
Registered: 12/7/04
Re: Single Trendline for multiple datasets
Posted: Jan 23, 2013 3:34 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Thursday, January 24, 2013 9:24:08 AM UTC+13, Charlotte wrote:
> I have a plot with multiple datasets plotted, and would like to plot on top a single trendline for all the datasets - is there an easy way to do this?

1. Assemble all the data into two vectors, x and y
x=[x1(:);x2(:); etc ];
2. Fit a line to the data using least squares:
coef=[x ones(length(x),1)]\y;
3. Define the line:
xfit=[min(x) max(x)];
yfit=coef(1)*xfit + coef(2);
4. Plot
plot(x,y,'bo',xfit,yfit,'r-')




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.