Use logic to determine if array contains a specific date

14 ビュー (過去 30 日間)
Michael Boyle
Michael Boyle 2021 年 12 月 1 日
編集済み: Stephen23 2021 年 12 月 1 日
I have an array where one column contains dates in the DD-MM-YYYY format. I am trying to use if statements to do certain things based on what the MM is of a given row. So far I have tried using strcmp( ) and contains( ), but I am not sure how to format it.
x = datetime(2021,12,13);
contains(x,'Dec');
strcmp(x,'Dec');
What is the correct way to format this so that matlab can identify the month component of the date in the array?
  1 件のコメント
Stephen23
Stephen23 2021 年 12 月 1 日
編集済み: Stephen23 2021 年 12 月 1 日
Note that the DATETIME object already includes the MONTH property, no other functions are required:
x = datetime(2021,12,13)
x = datetime
13-Dec-2021
x.Month==12
ans = logical
1

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

採用された回答

Star Strider
Star Strider 2021 年 12 月 1 日
Use the month function, then do the comparison —
x = datetime(2021,12,13);
y = datetime(2021,11,13);
TFx = month(x) == 12
TFx = logical
1
TFy = month(y) == 12
TFy = logical
0
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by