time | calls | line |
---|
| | 1 | function y = linspace(d1, d2, n)
|
| | 2 | %LINSPACE Linearly spaced vector.
|
| | 3 | % LINSPACE(X1, X2) generates a row vector of 100 linearly
|
| | 4 | % equally spaced points between X1 and X2.
|
| | 5 | %
|
| | 6 | % LINSPACE(X1, X2, N) generates N points between X1 and X2.
|
| | 7 | % For N = 1, LINSPACE returns X2.
|
| | 8 | %
|
| | 9 | % Class support for inputs X1,X2:
|
| | 10 | % float: double, single
|
| | 11 | %
|
| | 12 | % See also LOGSPACE, COLON.
|
| | 13 |
|
| | 14 | % Copyright 1984-2013 The MathWorks, Inc.
|
| | 15 |
|
| 6 | 16 | if nargin == 2
|
| | 17 | n = 100;
|
| 6 | 18 | else
|
| 6 | 19 | n = floor(double(n));
|
| 6 | 20 | end
|
| 6 | 21 | n1 = n-1;
|
| 6 | 22 | c = (d2 - d1).*(n1-1); %check intermediate value for appropriate treatment
|
| 6 | 23 | if isinf(c)
|
| | 24 | if isinf(d2 - d1) %opposite signs overflow
|
| | 25 | y = d1 + (d2/n1).*(0:n1) - (d1/n1).*(0:n1);
|
| | 26 | else
|
| | 27 | y = d1 + (0:n1).*((d2 - d1)/n1);
|
| | 28 | end
|
| 6 | 29 | else
|
| 6 | 30 | y = d1 + (0:n1).*(d2 - d1)/n1;
|
| 6 | 31 | end
|
| 6 | 32 | if ~isempty(y)
|
| 6 | 33 | y(1) = d1;
|
| 6 | 34 | y(end) = d2;
|
| 6 | 35 | end
|