matlab中Function函数的使用并写一个分段函数

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])

猜你喜欢

转载自blog.csdn.net/qq_44961737/article/details/105725404
今日推荐