Errorbars with standard deviation
Show older comments
How do I graph average bedtime in hours with a standard deviation error bar? I want the y axis to reflect times from 8pm to 6am. Also not sure how to scale x axis. The average bedtime was 1:37am and the std was 2.07.
5 Comments
John Doe
on 3 Jul 2019
I have had this problem for non time data and created the below solution:
%sData Row 1 = mean
%sData Row 2 = 3.std deviations
errorbar(1:1:7,sData(1,1:1:7),sData(2,1:1:7),'LineStyle','none','Marker','x')
xlim([0 8])
xticklabels({'' 'Data1' 'Data2' 'Data3' 'Data4' 'Data5' 'Data6' 'Data7' })
xlabel('X Label')
ylabel('Y Label')
title('Example Plot')
ax = gca;
ax.YGrid = 'on'
ax.YMinorGrid = 'on'
Adam Danz
on 3 Jul 2019
How are you averaging the time and computing the std? For example, what's the average of [23:59, 12:01] ? You taking the mean of a timeseries?
"I want the y axis to reflect times"
Use a datetime axis.
"How do I graph average bedtime in hours with a standard deviation error bar"
use errorbar()
Michael Molini
on 3 Jul 2019
Peter Perkins
on 8 Jul 2019
Michael, by your description you have 21 times; if that is a datetime array, it's easy to compute the mean (as a datetime) and the std dev (as a duration). But what's not clear is how many of those series you have. You mention scaling the x axis, but nothing more. I'm guessing maybe you have multiple subjects and want to plot each subject's mean with error bars.
This might be super easy if you have a timetable with all the data together, with a variable identifying which times go with which subject. Then you could use varfun, grouping by subject, to compute vectors of by-subject means and std devs, and plot them
But I think you're gonna need to provide more details.
Answers (0)
Categories
Find more on Errorbars 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!