function [x] = enforce_bounds(x, bounds) % VAR_ENCODE - Encodes the boundary limits for the variables x % % Inputs: % x = [ number_of_samples x number_of_variables ] input matrix of variables to be encoded % bounds = [ number_of_variables x 2 ] input matrix where the ith row is the valid bounds for the ith variable % % Outputs: % x_bounded = [ number_of_samples x number_of_variables ] with any variable that is outside of the domain truncated % % Written by: % -- % John L. Weatherwax 2006-08-28 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- % Check inputs: [N_samples,N_var] = size(x); assert( size(bounds,1)==N_var, 'bounds input must have N_var rows' ); assert( size(bounds,2)==2, 'bounds input must have two columns' ); % make sure all our initial input variables are within the required variables bounds before we encode them in binary: % for ii=1:N_var, inds = find( x(:,ii) < bounds(ii,1) ); x(inds,ii) = bounds(ii,1); inds = find( x(:,ii) > bounds(ii,2) ); x(inds,ii) = bounds(ii,2); end