Plotting mean across a graph
286 views (last 30 days)
Show older comments
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)
0 Comments
Answers (2)
Star Strider
on 17 Nov 2020
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.
0 Comments
Steven Lord
on 17 Nov 2020
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))
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!