绘制matlab函数

时间:2014-07-04 10:10:12

标签: matlab plot

让我们考虑以下图片

enter image description here

我写了以下代码

>> t=-0.01:0.005:0.02;
>> y=cos(2*pi*100*t);
>> plot(t,y)

得到了结果

enter image description here

为什么它如此粗糙?我也对它进行了采样

>> t=0:Ts:0.02;
>> y=cos(2*pi*100*t);
>> plot(t,y)

我有以下图片

enter image description here

这似乎没问题,但是关于第一个怎样才能让它更顺畅?

1 个答案:

答案 0 :(得分:1)

您正在从-0.010.02进行绘图,步骤为0.005,因此只有7个数据点。难怪为什么你的情节不顺畅......

您需要通过将0.005步骤更改为更小的步骤来优化采样。例如,从0.001开始(这将为您提供5倍的数据点)并进行实验,直到您对结果感到满意为止:

t=-0.01:0.001:0.02;