フィルターのクリア

How to extract all the data for a fixed year

4 ビュー (過去 30 日間)
peter huang
peter huang 2022 年 1 月 19 日
コメント済み: peter huang 2022 年 1 月 19 日
How to extract all the data for a fixed year and write a loop to get the annual data 1961, 1962...
  2 件のコメント
Rik
Rik 2022 年 1 月 19 日
That shouldn't be too hard. What have you tried?
peter huang
peter huang 2022 年 1 月 19 日
I tried to use the datenum command but I don't know how to get the whole year

サインインしてコメントする。

回答 (1 件)

Cris LaPierre
Cris LaPierre 2022 年 1 月 19 日
Load your data with readtable, with the dates imported as datetimes. Then you can use the isbetween function to identify the rows that are between two datetimes. If you want all the data within one year, you could also use logical indexing.
Your date format presented a small challenge that requried me to first load the date as a string and then convert it to a datetime.
opts = detectImportOptions("moving_windown_test.xlsx");
opts = setvartype(opts,1,"string");
data = readtable("moving_windown_test.xlsx",opts);
data.Var1 = datetime(data.Var1,"InputFormat","yyyyMMddHH");
data1964 = data.Var2(year(data.Var1)==1964)
data1964 = 8716×1
-226 -506 -766 -666 -456 -206 65 256 366 436

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by