MATLAB Answers

how to plot sine and cosine waves in one graph ?

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

Accepted Answer

Wayne King
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')

  0 Comments

Sign in to comment.

More Answers (4)

Sabarinathan Vadivelu
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);

  2 Comments

Stephen Cobeldick
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).

Sign in to comment.


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

  0 Comments

Sign in to comment.


Navadeep Ganesh U
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')

  0 Comments

Sign in to comment.


Ravi Kumar
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))

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags

No tags entered yet.


Translated by