2015-02-11 94 views

回答

2

使用逻辑索引!有关更多信息,请参见this link,逻辑索引是使用Matlab时熟悉的非常有用的东西!

x=0:0.01:2*pi; %// or whatever range of x you want 
f=sin(x); %// calculate sin(x) 
f(f<=0.5)=0.5; %// make the values of sin(x) less than or equal to 0.5 equal to 0.5 
f(f>=0.7)=0.7; 
plot(x,f) %// plot the result! 
+0

感谢您的回复。 – guru 2015-02-12 12:12:56