# how to plot sine and cosine waves in one graph ?

2.153 views (last 30 days)
Osama Abbas on 28 Sep 2012
Answered: Ravi Kumar on 24 Jan 2020 at 6:52
used for academic use

#### 1 Comment

Walter Roberson on 28 Sep 2012
Please read the guide to tags and retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags

Wayne King on 28 Sep 2012
It sounds like the OP wants this in one graph (not subplotted)
t = 0:0.01:(2*pi);
x = cos(t);
y = sin(t);
plot(t,x,'k'); hold on;
plot(t,y,'r-.');
axis([0 2*pi -1.5 1.5])
legend('cos(t)','sin(t)','Location','NorthEast')

### More Answers (4)

Sabarinathan Vadivelu on 28 Sep 2012
a = 10;
t = 0 : 0.01 : 10;
A = a*sin(t);
subplot(121),plot(t,A);
B = a*cos(t);
subplot(122),plot(t,B);

Lee Johnson on 2 Mar 2017
Thanks. What is subplot 121 and 122?
Stephen Cobeldick on 2 Mar 2017
@Lee Johnson: syntax not supported by MATLAB. Looks like MatPlotLib to me.
The MATLAB subplot documentation gives this syntax:
subplot(m,n,p)
and explains what m, n, and p are. There is of course no point in simply copying this info here when you can read in the documentation (see link).

Jaya Krishna on 25 Jun 2018
a = 10; t = 0 : 0.01 : 10; A = a*sin(t); subplot(121),plot(t,A);

Navadeep Ganesh U on 30 Nov 2019
t = 0:0.01:(2*pi);
x = cos(t);
y = sin(t);
plot(t,x,'k'); hold on;
plot(t,y,'r-.');
axis([0 2*pi -1.5 1.5])
legend('cos(t)','sin(t)','Location','NorthEast')

Ravi Kumar on 24 Jan 2020 at 6:52
x=0:0.1:2*pi;
plot(x,sin(x))
hold on
plot(x,cos(x))