How do plot 2 sine waves on the same plot with different line markers?

sine function (1)
time = 0: 4*pi
amplitude = -1:1
sine function (2)
phase shift of +pi/2 and -pi/2

 採用された回答

Image Analyst
Image Analyst 2020 年 4 月 11 日

0 投票

I have no idea what you mean by amp = 1:-1.
Anyway, start with this and adapt as needed:
% sine function (1)
% time = 0: 4*pi
t = linspace(0, 4*pi, 50)
period = 2 * pi;
% amp = 1:-1 No idea what this means.
amp = 1; % Let's just say it's 1.
y1 = amp * sin(2 * pi * t / period);
hFig = figure; % Bring up new figure.
plot(t, y1, 'b.', 'MarkerSize', 30);
grid on;
xlabel('t', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
% sine function (2)
% phase shift of +pi/2 and -pi/2
y2 = amp * sin(2 * pi * (t - pi/2) / period);
hold on;
plot(t, y2, 'rs', 'MarkerSize', 10, 'LineWidth', 2);
% sine function (3)
% phase shift of +pi/2 and -pi/2
y3 = amp * sin(2 * pi * (t + pi/2) / period);
plot(t, y3, 'm*', 'MarkerSize', 12, 'LineWidth', 2);
hFig.WindowState = 'maximized'
legend('y1', 'y2', 'y3');

6 件のコメント

Ghalia Bouraki
Ghalia Bouraki 2020 年 4 月 11 日
thanks! p.s. amp is amplitude
Ghalia Bouraki
Ghalia Bouraki 2020 年 4 月 11 日
which is the y-axis, would it still be correct?
Image Analyst
Image Analyst 2020 年 4 月 12 日
Would what still be correct? And how can a signal have two different amplitudes? One signal can only have one amplitude. If you have 2 amplitudes of -1, and 1, and 3 phases of -pi/2, 0, and +pi/2, then that would be 2*3 = 6 different signals to plot if you want all possible combinations.
Ghalia Bouraki
Ghalia Bouraki 2020 年 4 月 12 日
sorry let me rephrase, if the amplitude ranges from -1 to 1, would the given code give the right graph?
Image Analyst
Image Analyst 2020 年 4 月 12 日
No. You need to define the amplitude. I plotted just for one amplitude. What amplitudes do you have? What does "ranges" mean? You mean -1, -.99, -.98, .... +.98, +.99, 1, so like 201 different amplitudes to give 201 different signals? How about amp = rand(1,5) and you plot 5 different signals with 5 different amplitudes? I have no idea what "ranges" means to you. What was wrong with amp=1 like I did? You have to be specific.
Ghalia Bouraki
Ghalia Bouraki 2020 年 4 月 12 日
Ok. I understanbd now I was just confused, the code is great. Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by