Matlab 中划分段函数的曲线,非常急.

来源:百度知道 编辑:UC知道 时间:2024/06/03 06:12:18
>> clear
>> x1=-10:0.01:-1;
>> x2=-1:0.01:1;
>> x3=1:0.01:10;
>> x=[x1,x2,x3];
>> y1=x-0.5+1./(1+exp(x));
>> y2=0;
>> y3=x-0.5+1./(1+exp(x));
>> y=[y1,y2,y3];
>> plot(x,y)
??? Error using ==> plot
Vectors must be the same lengths.
如何修改啊,

你要的是这个结果吗?

clear
x1=-10:0.01:-1;
x2=-1:0.01:1;
x3=1:0.01:10;
x=[x1,x2,x3];
y1=x1-0.5+1./(1+exp(x1));
y2=zeros(1,length(x2)); %y2的长度不是一个点哦
y3=x3-0.5+1./(1+exp(x3));
y=[y1,y2,y3];
plot(x,y)