MATLAB 实现单位阶跃函数 x(t) = u(t) - u(t-2)
在 MATLAB 中可以使用以下代码来实现函数 x(t) = u(t) - u(t-2):
t = -5:0.01:5; % 定义时间范围
x = (t >= 0) - (t >= 2); % 计算函数值
plot(t, x, 'LineWidth', 2); % 绘制函数图像
xlabel('t'); % 设置 x 轴标签
ylabel('x(t)'); % 设置 y 轴标签
title('x(t) = u(t) - u(t-2)'); % 设置标题
grid on; % 添加网格线
这段代码首先定义了时间范围 t,然后通过逻辑运算符实现了函数 x(t) = u(t) - u(t-2) 的计算。接着,使用 plot 函数将函数图像绘制出来,并设置了轴标签和标题。最后,通过 grid on 命令添加了网格线以增强可读性。
你可以运行这段代码,然后在 MATLAB 中查看结果图像。
原文地址: https://www.cveoy.top/t/topic/RsG 著作权归作者所有。请勿转载和采集!