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

%*****************************************************************************80
%
%% closest_point_brute2() 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.
%
%  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 point to be checked.
%
%  Output:
%
%    integer near_index, the index of the nearest cell generator.
%
%    real near_dist: the distance of the nearest cell generator.
%
  rs = sum ( ( r - repmat ( s(1,:), nr, 1 ) ).^2 );

  [ near_dist, near_index ] = min ( rs );

  return
end
