4
|
1 function retval = linspace (x1, x2, n) |
|
2 |
|
3 # usage: linspace (x1, x2, n) |
|
4 # |
|
5 # Return a vector of n equally spaced points between x1 and x2 |
|
6 # inclusive. |
|
7 # |
|
8 # If the final argument is omitted, n = 100 is assumed. |
|
9 # |
|
10 # All three arguments must be scalars. |
|
11 # |
|
12 # See also: logspace |
|
13 |
|
14 if (nargin == 2) |
|
15 npoints = 100; |
|
16 elseif (nargin == 3) |
|
17 if (length (n) == 1) |
|
18 npoints = n; |
|
19 else |
|
20 error ("linspace: arguments must be scalars"); |
|
21 endif |
|
22 else |
|
23 error ("usage: linspace (x1, x2 [, n])"); |
|
24 endif |
|
25 |
|
26 if (npoints < 2) |
|
27 error ("linspace: npoints must be greater than 2"); |
|
28 endif |
|
29 |
|
30 if (length (x1) == 1 && length (x2) == 1) |
|
31 delta = (x2 - x1) / (npoints - 1); |
|
32 retval = zeros (1, npoints); |
|
33 for i = 0:npoints-1 |
|
34 retval (i+1) = x1 + i * delta; |
|
35 endfor |
|
36 else |
|
37 error ("linspace: arguments must be scalars"); |
|
38 endif |
|
39 |
|
40 endfunction |