mathwork中有关Function的介绍:https://ww2.mathworks.cn/help/matlab/ref/function.html
例如
实现下列分段函数:
画出的图像如图所示
代码如下
先建立一个函数文件并输入以下代码:
function m=fenduan(t) % 信号mt
to = 0.15;
m = 1.*(t>=0 & t<to/3)+(-2).*(t>to/3 & t<=2*to/3)+0.*(t<0 | t>2*to/3);
end
然后在命令行输入:
t=-0.1:0.001:0.2;
mt = fenduan(t);
plot(t,mt);
axis([-0.02 0.12 -2.5 2.5])