function nuniq = r8vec_sorted_unique_count ( n, a, tol ) %% R8VEC_SORTED_UNIQUE_COUNT counts the unique elements in a sorted R8VEC. % % Discussion: % % Because the array is sorted, this algorithm is O(N). % % Modified: % % 30 April 2004 % % Author: % % John Burkardt % % Parameters: % % Input, integer N, the number of elements of A. % % Input, real A(N), the sorted array to examine. % % Input, real TOL, a nonnegative tolerance for equality. % % Output, integer NUNIQ, the number of unique elements of A. % nuniq = 0; if ( n < 1 ) return; end nuniq = 1; for i = 2 : n if ( tol < abs ( a(i-1) - a(i) ) ) nuniq = nuniq + 1; end end