Potting sin() wave graph
4 ビュー (過去 30 日間)
古いコメントを表示
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 件)
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 –
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!