Calculate daily standard deviation from timetable

15 次查看(过去 30 天)
Hello, I want to calculate the mean max and mean min standard deviation of temperature data from a daily timetable.
t=timetable(dt, Temperature);
temperaturePerDayMin = retime(t2, 'daily', 'min');
tmpPerDayMin_std= std(temperaturePerDayMin.Temperature);
temperaturePerDayMax = retime(t2, 'daily', 'max');
tmpPerDayMax_std= std(temperaturePerDayMax.Temperature);
Right now tmpPerDayMin_std and tmpPerDayMax_std return only one value. How can I calculate the standard deviation for each day?

采纳的回答

Star Strider
Star Strider 2022-12-21
Try something like this —
DT = datetime('01-Dec-2022 00:00:00') + hours(0:720).';
Temperature = sin(2*pi*(0:numel(DT)-1)/24-0.5).'*12+5 + randn(size(DT))*1.5;
TT1 = timetable(DT, Temperature)
TT1 = 721×1 timetable
DT Temperature ____________________ ___________ 01-Dec-2022 00:00:00 -0.6988 01-Dec-2022 01:00:00 1.2667 01-Dec-2022 02:00:00 3.0934 01-Dec-2022 03:00:00 7.2162 01-Dec-2022 04:00:00 10.372 01-Dec-2022 05:00:00 12.655 01-Dec-2022 06:00:00 15.885 01-Dec-2022 07:00:00 18.277 01-Dec-2022 08:00:00 16.86 01-Dec-2022 09:00:00 16.837 01-Dec-2022 10:00:00 19.089 01-Dec-2022 11:00:00 14.336 01-Dec-2022 12:00:00 12.287 01-Dec-2022 13:00:00 9.4703 01-Dec-2022 14:00:00 2.5353 01-Dec-2022 15:00:00 -1.0999
figure
plot(TT1.DT, TT1.Temperature)
grid
DailyMax = retime(TT1, 'daily', 'max');
DailyMin = retime(TT1, 'daily', 'min');
DailySTD = retime(TT1, 'daily', @std);
TT2 = table(DailyMax.DT, DailyMax.Temperature, DailyMin.Temperature, DailySTD.Temperature, 'VariableNames',{'DT','Max','Min','StDv'})
TT2 = 31×4 table
DT Max Min StDv ___________ ______ _______ ______ 01-Dec-2022 19.089 -8.976 9.209 02-Dec-2022 16.877 -7.9704 8.9778 03-Dec-2022 18.891 -8.2106 8.3563 04-Dec-2022 17.053 -7.7505 8.9039 05-Dec-2022 19.937 -8.5247 8.9055 06-Dec-2022 17.545 -9.3624 8.7491 07-Dec-2022 19.835 -6.6562 8.0717 08-Dec-2022 18.21 -8.5766 8.8617 09-Dec-2022 17.416 -6.1877 8.1288 10-Dec-2022 17.298 -8.2496 8.4282 11-Dec-2022 18.21 -6.3769 8.891 12-Dec-2022 19.579 -8.3538 9.035 13-Dec-2022 20.088 -7.3316 8.5688 14-Dec-2022 19.397 -8.5091 8.7861 15-Dec-2022 17.578 -8.363 8.9894 16-Dec-2022 17.249 -8.5435 9.1342
The standard deviation of a single value is zero by definition, so it is only possible to calculate the standard deviation of all temperatures for a single day for that day.
It is possible to calculate the standard deviation for the maximum and minimum temperatures for several days (at least more than 1) and of course for the entire month.
.
  28 个评论
Ancalagon8
Ancalagon8 2023-1-30
Thank you @Star Strider. So far things are fine, but my concern is how can I add the time information of the min and max.
Star Strider
Star Strider 2023-1-30
As always, my pleasure!
I thought we already covered that problem at some point. By now I’ve lost track of where it is (although searching for it, I believe it was here).
It would be essentially the same approach.
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Preprocessing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by