function thin_dex = thin_index ( x, y, thin_factor ) % THIN_INDEX determines thinning indices for a X, Y data. % % Discussion: % % A set of X, Y data is given, that is presumably, not too far off % from being on a rectangular grid. % % The input value of THIN_FACTOR indicates by how much the data should % be thinned. % % The X and Y ranges are computed, and only those data points are % retained for which both X and Y lie in an appropriate subrange. % % For instance, a THIN_FACTOR of 2 would essentially save data % that lay in the black squares of a checkerboard. % % Modified: % % 17 June % % Author: % % John Burkardt % % Parameters: % % Input, real X(NODE_NUM), Y(NODE_NUM), the X and Y coordinates % of the nodes. % % Input, integer THIN_FACTOR, the thinning factor. % % Output, integer THIN_DEX(NODE_NUM), contains in (1:THIN_NUM) the % indices into X and Y of the vectors to be retained after thinning. % TRUE = 1; FALSE = 0; node_num = length ( x ); x_unique_num = 0; for i = 1 : node_num unique = TRUE; for j = 1 : x_unique_num if ( x(i) == x_unique(j) ) unique = FALSE; break; end end if ( unique ) x_unique_num = x_unique_num + 1; x_unique(x_unique_num) = x(i); end end sort ( x_unique ); y_unique_num = 0; for i = 1 : node_num unique = TRUE; for j = 1 : y_unique_num if ( y(i) == y_unique(j) ) unique = FALSE; break; end end if ( unique ) y_unique_num = y_unique_num + 1; y_unique(y_unique_num) = y(i); end end sort ( y_unique ); thin_num = 0; for i = 1 : node_num for j = 1 : x_unique_num-1 if ( x_unique(j) <= x(i) & x(i) <= x_unique(j+1) ) x_bin = j; break; end end for j = 1 : y_unique_num-1 if ( y_unique(j) <= y(i) & y(i) <= y_unique(j+1) ) y_bin = j; break; end end if ( mod ( y_bin, thin_factor ) == thin_factor / 2 & ... mod ( x_bin, thin_factor ) == thin_factor / 2 ) thin_num = thin_num + 1; thin_dex(thin_num) = i; end end