comparison scripts/general/cumtrapz.m @ 10549:95c3e38098bf

Untabify .m scripts
author Rik <code@nomad.inbox5.com>
date Fri, 23 Apr 2010 11:28:50 -0700
parents 1bf0ce0930be
children 35adf2a71f3f
comparison
equal deleted inserted replaced
10548:479536c5bb10 10549:95c3e38098bf
29 ## to @var{x}. 29 ## to @var{x}.
30 ## 30 ##
31 ## @seealso{trapz,cumsum} 31 ## @seealso{trapz,cumsum}
32 ## @end deftypefn 32 ## @end deftypefn
33 33
34 ## Author: Kai Habel <kai.habel@gmx.de> 34 ## Author: Kai Habel <kai.habel@gmx.de>
35 ## 35 ##
36 ## also: June 2000 Paul Kienzle (fixes,suggestions) 36 ## also: June 2000 Paul Kienzle (fixes,suggestions)
37 ## 2006-05-12 David Bateman - Modified for NDArrays 37 ## 2006-05-12 David Bateman - Modified for NDArrays
38 38
39 function z = cumtrapz (x, y, dim) 39 function z = cumtrapz (x, y, dim)
40 40
41 if (nargin < 1) || (nargin > 3) 41 if (nargin < 1) || (nargin > 3)
42 print_usage (); 42 print_usage ();
43 endif 43 endif
44 44
81 idx1 = cell (); 81 idx1 = cell ();
82 for i = 1:nd 82 for i = 1:nd
83 idx1{i} = 1:sz(i); 83 idx1{i} = 1:sz(i);
84 endfor 84 endfor
85 idx2 = idx1; 85 idx2 = idx1;
86 idx1{dim} = 2 : n; 86 idx1{dim} = 2 : n;
87 idx2{dim} = 1 : (n - 1); 87 idx2{dim} = 1 : (n - 1);
88 88
89 if (! have_x) 89 if (! have_x)
90 z = 0.5 * cumsum (x(idx1{:}) + x(idx2{:}), dim); 90 z = 0.5 * cumsum (x(idx1{:}) + x(idx2{:}), dim);
91 else 91 else
92 if (! size_equal (x, y)) 92 if (! size_equal (x, y))
93 error ("cumtrapz: x and y must have same shape"); 93 error ("cumtrapz: x and y must have same shape");
94 endif 94 endif
95 z = 0.5 * cumsum ((x(idx1{:}) - x(idx2{:})) .* 95 z = 0.5 * cumsum ((x(idx1{:}) - x(idx2{:})) .*
96 (y(idx1{:}) + y(idx2{:})), dim); 96 (y(idx1{:}) + y(idx2{:})), dim);
97 endif 97 endif
98 98
99 sz(dim) = 1; 99 sz(dim) = 1;
100 z = cat (dim, zeros (sz), z); 100 z = cat (dim, zeros (sz), z);
101 101