Plotting mean across a graph

조회 수: 282 (최근 30일)
Vaughn Beeson
Vaughn Beeson 2020년 11월 17일
답변: Steven Lord 2020년 11월 17일
Should be an easy question, but I'm having issues plotting a flat line across this 52x2 array, X being column 1 with datetime and Y being values from 0-100. The graph itself shows, but not the mean. I know that having 3 plot functions seems redundant but only the second one works and I dont know why
file='SearchesForFullMoon_Year.xlsx';
[X, Y]=readvars('SearchesForFullMoon_Year.xlsx');
Ymean=mean(Y,'all');
plot(X, Ymean,'r','LineWidth',1.5)
plot(X, Y, 'k','LineWidth',1.5)
hold on;
plot(Ymean, 'r','LineWidth',1.5)

답변 (2개)

Star Strider
Star Strider 2020년 11월 17일
Try this:
plot(xlim, [1 1]*Ymean, 'r','LineWidth',1.5)
The ‘Ymean’ value should be a constant, so it is necessary to plot it as a vector by multiplying it by [1 1].
Without your data to test this with, I am posting this as UNTESTED CODE. It should work.

Steven Lord
Steven Lord 2020년 11월 17일
If I understand what you want to do correctly, use the yline function.
x = datetime('today') + days(0:9);
y = 10*rand(size(x));
plot(x, y)
yline(mean(y))

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by