Since you are new, let us show you how Trendy works.

Close-button

Plot of Temperatures in Anchorage (Curve Fit - Linear)

  • Created by: Ned Gulley
  • Latest result: Plot created
  • Created on: 23 Nov 2011

This is an example of how to do a linear fit. Note that it uses the three-argument output form of polyfit to avoid numerical problems with the time vector.

Plot Image
t = time1155;
d = data1155(:);

% Only use that last 30 day's worth of data
keep = t>(now-30);
t = t(keep);
d = d(keep);

[p,S,mu] = polyfit(t,d,1);

% p1 is the equation for the linear fit to the data
p1 = [p(1)/mu(2) p(2)-p(1)*mu(1)/mu(2)];
tf = [t(1) t(end)];
df = polyval(p1,tf);

plot(t,d,'o:')
hold on
plot(tf,df)
datetick
Tags:

Add Tags


0 comments