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
採用された回答
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 件のコメント
thanks! p.s. amp is amplitude
which is the y-axis, would it still be correct?
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.
sorry let me rephrase, if the amplitude ranges from -1 to 1, would the given code give the right graph?
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.
Ok. I understanbd now I was just confused, the code is great. Thank you.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Multirate Signal Processing についてさらに検索
タグ
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)
