Reputation: 135
So I would like to plot a sine on MATLAB such that when |sin(x)| <= 1/2. Right now, here is my code:
figure(1)
t= [0:0.01:2*pi];
x = sin(t);
indices1 = find(abs(x)< 0.5);
plot(t(indices1), x(indices1));
ylim([-1, 1])
Output:
Is there a way to plot this such that the segments don't connect? Like, the first segment in which the sine function is within than 1/2 is connecting to the other segment in which it is within 1/2.
Upvotes: 1
Views: 127
Reputation: 26069
assign NaN
in the places you dont want to plot, for example
x2=x;
x2(abs(x)>0.5)=NaN;
plot(t, x2);
Upvotes: 2