how to plot sine and cosine waves in one graph ?

516 Ansichten (letzte 30 Tage)
Osama Abbas
Osama Abbas am 28 Sep. 2012
Kommentiert: Walter Roberson am 7 Apr. 2022
used for academic use
  5 Kommentare
Krishan Guiya
Krishan Guiya am 6 Apr. 2022
How can I plot cos(ax+b)
Walter Roberson
Walter Roberson am 7 Apr. 2022
syms x b
a = randn()
a = -1.0804
f = cos(a*x + b);
fsurf(f, [-10 10 -2*pi 2*pi])
xlabel('x'); ylabel('b')

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Weitere Antworten (4)

Sabarinathan Vadivelu
Sabarinathan Vadivelu am 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);
  3 Kommentare
Stephen23
Stephen23 am 2 Mär. 2017
Bearbeitet: Stephen23 am 2 Mär. 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).
Walter Roberson
Walter Roberson am 1 Feb. 2021
subplot 121 is archaic, no longer documented, but still works. It is interpreted as subplot(1, 2, 1)

Melden Sie sich an, um zu kommentieren.


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

Abdullah Rajput
Abdullah Rajput am 19 Aug. 2020
close all; clear all; clc;
t=[0:0.5:180]
x=sind(t);
plot(t,x),hold on
y=cosd(t);
plot(t,y)
legend('Sine wave','Cos wave')

Konstantin Kuzminov
Konstantin Kuzminov am 11 Mär. 2021
hold on not needed
x=0:0.1:2*pi;
plot(x,sin(x),"b",x,cos(x),"g");
"b" and "g" - color
  4 Kommentare
Walter Roberson
Walter Roberson am 12 Mär. 2021
I would not normally have mentioned a backwards compatibility like that now that we are 4 years on, but I suspect this question is getting read by people who are using old versions of MATLAB. (We are getting a rush of people using MATLAB from 2013 and 2015.)
Konstantin Kuzminov
Konstantin Kuzminov am 13 Mär. 2021
You are absolutely right. This is very useful information, because not everyone has the latest versions, they are not required for simple tasks. Correct syntax - 50% success.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by