Superimposing Graphs with large difference in Y-axis values

9 ビュー (過去 30 日間)
Starry
Starry 2022 年 1 月 14 日
コメント済み: Starry 2022 年 1 月 15 日
I have a graph a=exp(-0.2*x).*sin(x), with x in the range x = 0:pi/20:6*pi. I want to superimpose another graph z=exp(3*x).*cos(x) with the same x range to the other graph. I have tried it, the code is pos_combined_code. The graph displayed is pos_combined. It seems the a graph is not displayed. Only the z graph is displayed. I suspect the reason is the y-axis value for z is much bigger than a, and therefore it is impossible to display those 2 graphs together. I have attached graph a when plotted alone(graph a alone.jpg).
Anyone knows how to display these 2 graphs together in this situation? Thanks.

回答 (1 件)

Simon Chan
Simon Chan 2022 年 1 月 14 日
Try function yyaxis
  2 件のコメント
Kevin Holly
Kevin Holly 2022 年 1 月 14 日
x = 0:pi/20:6*pi
x = 1×121
0 0.1571 0.3142 0.4712 0.6283 0.7854 0.9425 1.0996 1.2566 1.4137 1.5708 1.7279 1.8850 2.0420 2.1991 2.3562 2.5133 2.6704 2.8274 2.9845 3.1416 3.2987 3.4558 3.6128 3.7699 3.9270 4.0841 4.2412 4.3982 4.5553
a=exp(-0.2*x).*sin(x)
a = 1×121
0 0.1516 0.2902 0.4132 0.5184 0.6043 0.6700 0.7151 0.7397 0.7444 0.7304 0.6991 0.6524 0.5923 0.5211 0.4414 0.3556 0.2661 0.1755 0.0861 0.0000 -0.0809 -0.1548 -0.2204 -0.2765 -0.3224 -0.3575 -0.3815 -0.3946 -0.3971
z=exp(3*x).*cos(x)
z = 1×121
1.0e+24 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
figure
plot(x,a)
figure
plot(x,z)
figure
plot(x,a)
hold on
plot(x,z)
figure
yyaxis left
plot(x,a)
yyaxis right
plot(x,z)
Starry
Starry 2022 年 1 月 15 日
Thanks Simon Chan and Kevin Holly.

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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by