How do plot 2 sine waves on the same plot with different line markers?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
sine function (1)
time = 0: 4*pi
amplitude = -1:1
sine function (2)
phase shift of +pi/2 and -pi/2
Accepted Answer
Image Analyst
on 11 Apr 2020
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 Comments
Ghalia Bouraki
on 11 Apr 2020
thanks! p.s. amp is amplitude
Ghalia Bouraki
on 11 Apr 2020
which is the y-axis, would it still be correct?
Image Analyst
on 12 Apr 2020
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
on 12 Apr 2020
sorry let me rephrase, if the amplitude ranges from -1 to 1, would the given code give the right graph?
Image Analyst
on 12 Apr 2020
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
on 12 Apr 2020
Ok. I understanbd now I was just confused, the code is great. Thank you.
More Answers (0)
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Tags
See Also
on 11 Apr 2020
on 12 Apr 2020
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)