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

조회 수: 2,094(최근 30일)
Osama Abbas 28 Sep 2012
답변: Ravi Kumar 24 Jan 2020 6:52

#### 댓글 수: 1

Walter Roberson 28 Sep 2012

로그인 to comment.

### 채택된 답변

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

로그인 to comment.

### 추가 답변(4개)

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

Lee Johnson 2 Mar 2017
Thanks. What is subplot 121 and 122?
Stephen Cobeldick 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).

로그인 to comment.

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

#### 댓글 수: 0

로그인 to comment.

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

로그인 to comment.

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

#### 댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

### 태그

아직 태그를 입력하지 않았습니다.