Reputation: 119
I am trying to plot cos(x) and sin(x) in a graph. Here is my code:
t = -pi:0.01:(pi);
x = cos(t);
y = sin(t);
plot(t,x,'b'); hold on;
plot(t,y,'r');
axis([-pi pi -1 1])
legend('cos(t)','sin(t)','Location','NorthWest')
title('Plot of cos(x) and sin(x) between -2\pi and 2\pi')
I want to change the numbers on the y-axis so that I will only have -pi, -pi/2, 0 ,pi pi Any help?
Upvotes: 0
Views: 93
Reputation: 13886
You probably want:
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabels',{'-\pi','-\pi/2','0','\pi/2','\pi'})
Upvotes: 1