How to extract Jan and feb dates from an array of date strings?

1 回表示 (過去 30 日間)
JFz
JFz 2018 年 7 月 27 日
コメント済み: JFz 2018 年 8 月 3 日
Hi,
I have an array of cells of date string. I need to extract all the dates in Jan and Feb. How to do that? Thanks a lot!
  3 件のコメント
JFz
JFz 2018 年 7 月 27 日
Something I created with {'1/1/2018'; '2/1/2018'; ...}

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

採用された回答

Stephen23
Stephen23 2018 年 7 月 27 日
>> C = {'1/1/2018'; '2/1/2018'; '12/31/2018'};
>> X = cellfun('isempty',regexp(C,'^[12]/','once'));
>> D = C(~X)
  3 件のコメント
JFz
JFz 2018 年 7 月 30 日
This works. Thank you!

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

その他の回答 (1 件)

Peter Perkins
Peter Perkins 2018 年 8 月 3 日
If possible, don't do this with text. Convert to datetimes:
>> d = datetime(2018,randi(6,10,1),1)
d =
10×1 datetime array
01-Jan-2018
01-Mar-2018
01-Jan-2018
01-Mar-2018
01-Jan-2018
01-May-2018
01-Mar-2018
01-Jan-2018
01-Feb-2018
01-Mar-2018
>> d(d.Month==1 | d.Month==2)
ans =
5×1 datetime array
01-Jan-2018
01-Jan-2018
01-Jan-2018
01-Jan-2018
01-Feb-2018
  1 件のコメント
JFz
JFz 2018 年 8 月 3 日
Thank you!

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

カテゴリ

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

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by