1 2 3 4 5 6
function val = clamp(m, n, M) % returns n if n is between m and M, otherwise % m if n < m % M if n > m val = min(max(m, n), N) end