필터 지우기
필터 지우기

Potting sin() wave graph

조회 수: 2 (최근 30일)
Christopher Clarke
Christopher Clarke 2020년 6월 4일
답변: Ayush Laddha 2020년 6월 18일
Hi,
i am trying to plot three sign wave graph in one figure but the graphs are not coming out as intended.
wgn: Generate 60 random sample; Amplitude range -0.2 to 0.2
wgn2: wgn*3
A = 2 ;
f = 100;
n = (0:60);
fs = 2000;
x = A*sin(2*pi*n*(f/fs));
t = x/1000;
wgn = rand(1,61)*0.4-0.2;
wgn2 = wgn*3;
subplot (3,1,1)
plot(x,t,'m--d')
xlabel ('x')
ylabel ('time (ms)')
title ('Graph')
grid
subplot (3,1,2)
plot (wgn,t,'b-x')
xlabel ('wgn')
ylabel ('time (ms)')
grid
subplot(3,1,3)
plot((x+wgn2),t,'g-*')
xlabel ('x+wgn2')
ylabel('time (ms)')
grid
  댓글 수: 1
Alberto Mora
Alberto Mora 2020년 6월 4일
Please explain better the problem

댓글을 달려면 로그인하십시오.

답변 (1개)

Ayush Laddha
Ayush Laddha 2020년 6월 18일
From your explanation of the question, I infer that you want to have all 3 graphs in a single plot. You can make use of the hold on and hold off commands to do so. You can also use the legend function to specify appropriate details for every line. You also mentioned in the question that you wanted to have 60 random samples however, I can see that your code generates 61 random samples. I have fixed the code for that too.
A = 2;
f = 100;
n = (1:60);
fs = 2000;
x = A*sin(2*pi*n*(f/fs));
t = x/1000;
wgn = rand(1,60)*0.4-0.2;
wgn2 = wgn*3;
plot(x,t,'m--d')
hold on
plot (wgn,t,'b-x')
plot((x+wgn2),t,'g-*')
grid on
title('Graph')
ylabel('time')
legend("x", "wgn", "x+wgn2", "Location", "northwest")
hold off
You can refer to the documentation of the functions for further info –

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by