Trying to plot two lines in the same figure, doesn't work?

Hi everyone. Im trying to have plot(lesteps,leerros) and plot(trapsteps,traperrors) on the same figure. When I just try to plot one of them it gives me the correct line
[lesteps,leerrors] =leftEndpointAPPROX(12); %vectors of log of steps and errors for the LE Rectangle rule
[trapsteps,traperrors] = trap2(12); %vectors of log of steps and errors for the trapezoid rule
slopeLE = (leerrors(2)-leerrors(1)/(lesteps(2)-lesteps(1)));
slopeTrap = (traperrors(2)-traperrors(1)/(trapsteps(2)-trapsteps(1)));
plot(lesteps,leerrors)
hold on
%plot(trapsteps,traperrors)
title('LogvLog of Trapezoid and LE Rectangle Rules Prob3HW4')
xlabel('log(n)')
ylabel('log(errors)')
legend({'LE Rectangle Rule','Trapezoid Rule'},'Location','southwest')
annotation('textbox', [0.25, 0.1, 0.1, 0.1], 'String', "Slope of LE Rectangle Rule: " + slopeLE)
annotation('textbox', [0.45, 0.1, 0.1, 0.1], 'String', "Slope of Trapezoid Rule: " + slopeTrap)
hold off
When I try to plot both of them by uncommenting plot(trapsteps,traperrors) , this happens! I have no idea what I'm doing incorrectly, any guidance would be greatly appreciated!

1 件のコメント

Setsuna Yuuki.
Setsuna Yuuki. 2020 年 11 月 17 日
the values of the variables are very small, so when you graph the second variable it looks like a straight line.

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

 採用された回答

VBBV
VBBV 2020 年 11 月 17 日

2 投票

%if true
plot(lesteps,leerros)
yyaxis right
plot(trapsteps,traperrors)
Try this to plot The graph with two axes showing distinct slopes

1 件のコメント

Emily Gonzalez
Emily Gonzalez 2020 年 11 月 18 日
Amazing thank you so so much! It worked! Let's say I wanted to add too more plots to this, what would I have to do?

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2020b

タグ

質問済み:

2020 年 11 月 17 日

コメント済み:

2020 年 11 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by