function [x,adjusted]=check_bound(x,xleft,xright) % check if number out of bound and then assign it to the mid of the region if xleft > xright % sanity check for bounds tmp=xright; xright=xleft; xleft=tmp; end if xxright x=(xleft+xright)/2; adjusted = true; else adjusted = false; end