필터 지우기
필터 지우기

Converting cell array containing date strings to weekday?

조회 수: 2 (최근 30일)
Jinah Lee
Jinah Lee 2017년 4월 1일
댓글: Star Strider 2017년 4월 1일
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
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
Jinah Lee 2017년 4월 1일
This is part of 1st column of rawData. So 1st column of rawdata is a cell array containing bunch of data strings.. and I want to change this into weekday so that I could calculate average of certain values per weekday..
'Date'
'2015-01-01'
'2015-01-02'
'2015-01-03'
'2015-01-04'
'2015-01-05'
'2015-01-06'
'2015-01-07'
'2015-01-08'
'2015-01-09'
Star Strider
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')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by