Trying to add horizontal line on a graph

2 ビュー (過去 30 日間)
Jack Lakeman
Jack Lakeman 2016 年 11 月 8 日
コメント済み: Walter Roberson 2016 年 11 月 8 日
So im trying to add a horizontal line to to show the mean gradient to the graph on the bottom.
The mean is -0.0714 and i want to draw this line as a dotted line. iv tried all sorts of things on this forum but cant seem to get it
Thanks in advance

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 11 月 8 日
XL = xlim();
plot( XL, [TheMean, TheMean])
  2 件のコメント
Jack Lakeman
Jack Lakeman 2016 年 11 月 8 日
Thank you!
But it seems to draw a line 3/4 of the graph and not through the entire graph. And is there any way to change the colour and have it dotted?
It gives me an error message when i try to do it. i must be doing it wonrg
Walter Roberson
Walter Roberson 2016 年 11 月 8 日
Example:
plot(x,y)
x = 1:30;
y = sin(x)+x;
TheMean = mean(y);
plot(x,y)
hold on
XL = xlim();
plot(XL, [TheMean TheMean], 'g--')
hold off

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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by