Errorbars with standard deviation

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 个评论

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'
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()
I’m computing the mean from a time span of 21 days. The data comes from a struc called “diary”. Within this struc is an array for bedtimes (21x1) The variable is: bedtime = (diary.bedTime - floor(diary.bedTimes)).*24; avgbedtime = mean(bedtime(:)); SDbedtimr = std(bedtime.1);
What is bedtime(:)? Is it a vector of date/times in datetime format? Is it part of a timetable?
I recommend organizing your data into a timetable and then using retime() to calculate means and standard deviations.
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.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Errorbars 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by