MATLAB: How to restrict the range

MATLAB

I want to restrict the output of the arc cosine to be in the range [-1,1], but I want to know if there is built-in Matlab function for this task and if it is possible for example merge @max & @min simultaneoulsy in the function bsxfun to achieve this task.

Best Answer

I do not see why you need bsxfun for this. If X is your signal, this statement restricts X between -1 and 1
X = [0.5 1 2 -2 -1 -0.5 0]
OUT = min(max(X,-1),1)
You can create an (anonymous) function for this, if you need it a lot.
minmax = @(x,a,b) max(min(x,a),b) % restricts input X between a and b