spence21.m 585 B

123456789101112131415161718192021222324252627
  1. function yhat=spence21(y)
  2. % function for Spencer's 21-point graduation rule.
  3. % set out following Spencer's hand-calculation method,
  4. % which isn't the shortest computer program!
  5. oten = ones(10,1);
  6. n = length(y);
  7. y = [ oten*y(1); y; oten*y(n) ];
  8. n = length(y);
  9. k = 4:(n-3);
  10. y1 = -y(k-3) + y(k-1) + 2*y(k) + y(k+1) -y(k+3);
  11. n = length(y1);
  12. k = 4:(n-3);
  13. y2 = y1(k-3)+y1(k-2)+y1(k-1)+y1(k)+y1(k+1)+y1(k+2)+y1(k+3);
  14. n = length(y2);
  15. k = 3:(n-2);
  16. y3 = y2(k-2)+y2(k-1)+y2(k)+y2(k+1)+y2(k+2);
  17. n = length(y3);
  18. k = 3:(n-2);
  19. y4 = y3(k-2)+y3(k-1)+y3(k)+y3(k+1)+y3(k+2);
  20. yhat = y4/350;
  21. return;