思路:
找出y<0.5对应的下标,记为index_smaller_than_0d5
找出y>=0.5对应的下标,记为index_larger_than_0d5
分别采用相应的格式进行画图。
代码:
close all;
x=linspace(0,6*pi,1000);
y=sin(x);
index_smaller_than_0d5=find(y<0.5);
plot(x(index_smaller_than_0d5),y(index_smaller_than_0d5),'r.');hold on;
index_larger_than_0d5=find(y>=0.5);
plot(x(index_larger_than_0d5),y(index_larger_than_0d5),'b.');hold on;
xlabel('x');
ylabel('y=sin(x)');
图像: