I'm trying to plot the function: x(t) = 20*cos(2*pi*500*t). When I try to do this, nothing is plotted and i'm not sure why. The x and y limits are also incorrect. What can i do to fix this?
2 次查看(过去 30 天)
显示 更早的评论
if true
t = 0:0.005;
xlim([-0.002 0.002])
ylim([-20 20])
y = 20*cos(2*pi*500*t)
plot (t,y)
end
0 个评论
采纳的回答
John D'Errico
2018-1-18
编辑:John D'Errico
2018-1-18
So what do you think happens when you write this?
t = 0:0.005;
Did you look at the results of that operation? Why not? Always check every line when you are not sure what you are doing. Even if you think you are sure, knowing what happened on every line is crucial. I'm asking the above questions because I think you do not understand some basic aspects of MATLAB. That suggests you have not bothered to read basic things, like the getting started documentation. So lets look at t:
t
t =
0
Have you read the help for the colon operator? Why not?
a:b generates a sequence of numbers, running from a to b with a step of 1, by default. If the final step will exceed b, then the colon sequence stops before it bypasses b.
So what is 0+1? Does it exceed 0.005? So how many elements in the sequence of numbers t should you expect?
You might consider using linspace instead of colon to create t as a vector. But really, if you have no clue what colon does, you need to read the documentation.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!