Converting cell array containing date strings to weekday?
古いコメントを表示
Hello, I have a 366*1 cell array containing date string such as '2015-01-01'. I want to change this date string to weekday such as Monday, Tuesday..etc. What function should I have to use? Thanks!
回答 (1 件)
Star Strider
2017 年 4 月 1 日
Use the weekday function:
date_cell = {'2015-01-01'; '2015-01-02'; '2015-01-03'};
dn = datenum(date_cell, 'yyyy-mm-dd');
[~,DayOfWeek] = weekday(dn,'long')
DayOfWeek =
3×8 char array
'Thursday'
'Friday '
'Saturday'
4 件のコメント
Jinah Lee
2017 年 4 月 1 日
Star Strider
2017 年 4 月 1 日
My pleasure.
I have no idea what your ‘rawData’ has. The syntax you are using does not appear to be correct.
Try this:
dn = datenum(rawData{:}(:,1), 'yyyy-mm-dd');
[~,DayOfWeek] = weekday(dn,'long')
Without your ‘rawData’ cell array, I cannot test this, so I am guessing this is the correct way to address your cell array.
Jinah Lee
2017 年 4 月 1 日
Star Strider
2017 年 4 月 1 日
I had to create a cell array that resembled yours in order to get the addressing correct.
This works:
rawData = {'Date' 'Number'; '2015-01-01' 10; '2015-01-02' 5; '2015-01-03' 7};
dv = {rawData{2:end,1}};
dn = datenum(dv, 'yyyy-mm-dd');
[~,DayOfWeek] = weekday(dn,'long')
カテゴリ
ヘルプ センター および File Exchange で Calendar についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!