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?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Caleb Wilson
am 18 Jan. 2018
Bearbeitet: John D'Errico
am 18 Jan. 2018
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 Kommentare
Akzeptierte Antwort
John D'Errico
am 18 Jan. 2018
Bearbeitet: John D'Errico
am 18 Jan. 2018
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!