Can someone provide the syntax for selecting monthly rowtimes from a timeteble? I would like to select various months. For example, Nov., Dec., Jan., Feb.
Here is what I'm trying:
The 'wintertime' variable and the follwing lines are also screwed up.
Thanks.
% Create new timetables at differing scales.
% Extract the month record
monthofTT = month(TT.Time);
% Determine which records are between November and March (months 1:3 and
% 11:12)
wintertime = [1,3;11,12]; % [start, end] of desired months
wintermonths = monthofTT >= winter(1) & wintertime <= winter(2);
% Isolate all row in winter months
TTwinter = TT(month(TT.Time(winterrmonths)), :);

 採用された回答

dpb
dpb 2021 年 9 月 23 日
編集済み: dpb 2021 年 9 月 24 日

0 投票

To use the numeric months,
wintertime = [1:3 11:12]; % [start, end] of desired months
TTwinter = TT(ismember(month(TT.Time),wintertime), :);

6 件のコメント

Eric Escoto
Eric Escoto 2021 年 9 月 23 日
Hi dpb,
I tried this. Got an error.
Error using matlab.internal.datatypes.getChoice (line 77)
Month type must be 'monthofyear', 'name', or 'shortname'.
Error in datetime/month (line 1090)
kind = getChoice(kind,["MonthOfYear" "MoY" "Name" "LongName" "ShortName"],[1 1 2 2 3], ...
dpb
dpb 2021 年 9 月 24 日
Well, without your actual time table, I just used the variable name you gave; it's unknowable w/o the actual table just what you had/have done.
Attach it as a .mat file...
Eric Escoto
Eric Escoto 2021 年 9 月 24 日
Sure thing.
dpb
dpb 2021 年 9 月 24 日
My eyes got crossed last night -- it'd been a long day working on scholarship billings for the local nonprofit college foundation already by that time...there's a misplaced parenthesis in the original. It's at the end of the ismember argument list and is missing one to close the argument to month().
Corrected above. Tested here, works fine...
Eric Escoto
Eric Escoto 2021 年 9 月 24 日
Ah I see it. Thanks!
dpb
dpb 2021 年 9 月 25 日
Was pretty obvious when not so tired...sorry didn't catch it at first.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Tables についてさらに検索

製品

リリース

R2021b

質問済み:

2021 年 9 月 23 日

コメント済み:

dpb
2021 年 9 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by