function [ near_index, near_dist ] = closest_point_brute3 ( m, nr, r, s )

%*****************************************************************************80
%
%% closest_point_brute3() finds the nearest R point to an S point.
%
%  Discussion:
%
%    We are given R, a set of NR points in M dimensions.
%
%    We are given S, a point in M dimensions.
%
%    We seek the index J of the point R(J)
%    which is nearest to S over all points in R.
%
%    Modified in accordance with suggestions by Gene Cliff, 08 July 2010.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 August 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, the spatial dimension.
%
%    integer NR, the number of cell generators.
%
%    real R(NR,M), the cell generators.
%
%    real S(1,M), the points to be checked.
%
%  Output:
%
%    integer near_index: the index of the nearest cell generator.
%
%    real near_dist: the distance of the nearest cell generator.
%
  d1 = r - s(1,:);
  d2 = sum ( d1 .* d1 );
  [ near_dist, near_index ] = min ( d2 );

  return
end
