home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / softsys / matlab / 121 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.6 KB  |  87 lines

  1. Newsgroups: comp.soft-sys.matlab
  2. Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!forsythe.stanford.edu!nova!maurer
  3. From: Michael Maurer <maurer@nova.stanford.edu>
  4. Subject: SOURCE: clocksub.m - compute time difference
  5. Message-ID: <maurer.727751379@nova.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: STAR Lab, Stanford University, California USA
  8. Date: 23 Jan 93 01:09:39 GMT
  9. Lines: 76
  10.  
  11. Hoping to start a trend, here is an unsolicited matlab m-file.
  12. CLOCKSUB computes the number of seconds elapsed between two calls to
  13. CLOCK.  (Has trouble with year boundaries due to leap-year
  14. irregularities.)  Suggested improvements are welcome.
  15.  
  16. #! /bin/sh
  17. # This is a shell archive, meaning:
  18. # 1. Remove everything above the #! /bin/sh line.
  19. # 2. Save the resulting text in a file.
  20. # 3. Execute the file with /bin/sh (not csh) to create the files:
  21. #    clocksub.m
  22. #    mod.m
  23. # This archive created: Fri Jan 22 16:57:09 1993
  24. export PATH; PATH=/bin:$PATH
  25. echo shar: extracting "'clocksub.m'" '(583 characters)'
  26. if test -f 'clocksub.m'
  27. then
  28.     echo shar: will not over-write existing file "'clocksub.m'"
  29. else
  30. sed 's/^XX//' << \SHAR_EOF > 'clocksub.m'
  31. XXfunction dt=clocksub(t2,t1)
  32. XX
  33. XX%CLOCKSUB
  34. XX%    dt=clocksub(t2,t1) returns the time difference in seconds between
  35. XX%    the two times (t2-t1).  See CLOCK for format of t1 and t2.
  36. XX
  37. XX%    Michael Maurer, 25 June 1992
  38. XX%    Copyright (c) 1993 by Michael Maurer
  39. XX
  40. XXd=t2-t1;
  41. XXmonths=[0 31 31 28 30 31 30 31 31 30 31 30 31];
  42. XXif d(1),
  43. XX   error('can''t handle different years yet (leap day complication)')
  44. XXend
  45. XX
  46. XXdt=d(1);
  47. XXm1=sum(months(1:t1(2))) + ((mod(t1(1),4)==0) & t1(2)>3);
  48. XXm2=sum(months(1:t2(2))) + ((mod(t2(1),4)==0) & t2(2)>3);
  49. XXdt=dt*365 + (m2-m1) + d(3);
  50. XXdt=dt*24 + d(4);
  51. XXdt=dt*60 + d(5);
  52. XXdt=dt*60 + d(6);
  53. SHAR_EOF
  54. if test 583 -ne "`wc -c < 'clocksub.m'`"
  55. then
  56.     echo shar: error transmitting "'clocksub.m'" '(should have been 583 characters)'
  57. fi
  58. fi # end of overwriting check
  59. echo shar: extracting "'mod.m'" '(225 characters)'
  60. if test -f 'mod.m'
  61. then
  62.     echo shar: will not over-write existing file "'mod.m'"
  63. else
  64. sed 's/^XX//' << \SHAR_EOF > 'mod.m'
  65. XXfunction y=mod(x,n)
  66. XX%MOD    Y = MOD(X, N) returns X modulo N.
  67. XX
  68. XX%    Michael Maurer, Sep 10 1990
  69. XX%    Copyright (c) 1993 by Michael Maurer
  70. XX
  71. XXif (length(n)~=1),
  72. XX   error('The base N must be size 1x1.');
  73. XXend
  74. XX
  75. XXy = abs(x - (floor(x/n)*n));
  76. SHAR_EOF
  77. if test 225 -ne "`wc -c < 'mod.m'`"
  78. then
  79.     echo shar: error transmitting "'mod.m'" '(should have been 225 characters)'
  80. fi
  81. fi # end of overwriting check
  82. #    End of shell archive
  83. exit 0
  84. --
  85. ______________________________________________________________________
  86. Michael Maurer          maurer@nova.stanford.edu        (415) 723-1024
  87.