function c = intspace ( a, b, n )
%*****************************************************************************80
%
%% intspace() returns roughly equally spaced integers in an interval.
%
% Discussion:
%
% intspace() is a sort of "linspace()" for integers.
%
% An interval is defined by integers A <= B.
%
% If possible, a vector C of N integers is to be determined, with
% C(1) = A and C(N) = B.
%
% So far as possible, the entries of C should be equally spaced in [A,B].
%
% However, if B-A+1 < N, then we simply return C = A:B.
%
% A use for this code can be imagined in which a large array of data
% has been computed, and it is desired to make a plot. However, displaying
% all the data might result in an ugly plot, or one that takes too long
% to display. One can then specify an index set like
% c = intspace ( 1, max, 100 )
% and restrict the plot to the data indexed by C.
%
% Similarly, it might be desired to print out sample values of a large
% array of data; this function would make it easy to do this in a
% fairly regular fashion.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 22 July 2022
%
% Author:
%
% John Burkardt.
%
% Input:
%
% integer A, B: the left and right endpoints.
%
% integer N: the number of samples desired.
%
% Output:
%
% integer C[*]: the sample values. The first and last entries
% of C will be A and B respectively. The number of entries in C
% will be min ( N, B+1-A). The entries of C will be roughly
% equally spaced.
%
if ( b + 1 - a <= n )
c = a : b;
else
i = n - 1 : -1 : 0;
j = 0 : n - 1;
c = round ( ( i * a + j * b ) / ( n - 1 ) );
end
return
end