Creating Own Time Variable from Datetime Data

5 ビュー (過去 30 日間)
Cam Pine
Cam Pine 2022 年 9 月 19 日
回答済み: Stephen23 2022 年 9 月 19 日
Hello! I am currently trying to create a timeseries plotting of wind averages. Currently, my time variable is in the format MM/DD,YYYY HH:MM, however, it repeats for 20 data points until it changes to the next minute. Example, 08/26/2020 12:00 --> 20 values --> 21st data point 08/26/2020 12:01. I am trying to create my own time variable for a six-hour period that I am interested in plotting for a time vs wind plot. I originally used:
<< plot(time1(18571:1:25552),wavg1(18571:1:25552)); where 18571-->25552 corresponds to the datapoint for 04:00 -- 10:00 local time of the interesting period.
This code worked, however, it made the plot look funky with the multitude of values for each minute.
I am now trying:
<< timesec = [14400:3:36000] 14400/3600(seconds in an hour) = 4 36000/3600 = 10
I hope someone can help me convert my datetime time variable into working with a new time variable, thanks.

採用された回答

Stephen23
Stephen23 2022 年 9 月 19 日
"I hope someone can help me convert my datetime time variable into working with a new time variable, thanks. "
Your question does not show any datetime variable.
Using datetime & duration objects is simpler than messing around with fractions like you are doing:
DT = datetime(2020,8,26,4,0,0):seconds(3):datetime(2020,8,26,10,0,0);
DT = DT(:)
DT = 7201×1 datetime array
26-Aug-2020 04:00:00 26-Aug-2020 04:00:03 26-Aug-2020 04:00:06 26-Aug-2020 04:00:09 26-Aug-2020 04:00:12 26-Aug-2020 04:00:15 26-Aug-2020 04:00:18 26-Aug-2020 04:00:21 26-Aug-2020 04:00:24 26-Aug-2020 04:00:27 26-Aug-2020 04:00:30 26-Aug-2020 04:00:33 26-Aug-2020 04:00:36 26-Aug-2020 04:00:39 26-Aug-2020 04:00:42 26-Aug-2020 04:00:45 26-Aug-2020 04:00:48 26-Aug-2020 04:00:51 26-Aug-2020 04:00:54 26-Aug-2020 04:00:57 26-Aug-2020 04:01:00 26-Aug-2020 04:01:03 26-Aug-2020 04:01:06 26-Aug-2020 04:01:09 26-Aug-2020 04:01:12 26-Aug-2020 04:01:15 26-Aug-2020 04:01:18 26-Aug-2020 04:01:21 26-Aug-2020 04:01:24 26-Aug-2020 04:01:27
Y = rand(7201,1);
plot(DT,Y)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by