MATLAB: I want to plot a piecewise function. So could someone tell me what N, a positive value, would be

I want to plot a piecewise function that has
x=-2*pi:0.001:-2*pi
does not use a loop or the "find" function,
y = {tan(x) if abs(tan(x))<=N,
N if tan(x)>N,
-N if tan(x)<-N}

Best Answer

>> x = -2*pi:0.001:2*pi;
>> N = 3;
Method one: min and max:
>> y = max(-N,min(N,tan(x)));
Method two: logical indexing:
>> y = tan(x);
>> y(y>+N) = +N;
>> y(y<-N) = -N;
and plotted:
>> plot(x,y)