How to convert day information to a number?

조회 수: 1 (최근 30일)
John Lee
John Lee 2021년 9월 24일
댓글: Star Strider 2021년 9월 24일
How can I convert day information to a number?
For instance, Mon to 1, Tue to 2, etc.
Fo from character to number data.

채택된 답변

Star Strider
Star Strider 2021년 9월 24일
Experiment with something like this —
daynr = @(x) find(strcmp(x, {'Mon','Tue','Wed','Thu','Fri','Sat','sun'}));
nr = daynr('Thu')
nr = 4
Everything depends on the context it will be used in, so this is just an example of one approach.
.
  댓글 수: 2
John Lee
John Lee 2021년 9월 24일
Oh, this is what I wanted, thanks. I modified your answer with a 100-by-1 column string vector (i.e. "day" variable)
%%
clear
load day % 100-by-1 string data
daynr = @(x) find(strcmp(x, {'Mon','Tue','Wed','Thu','Fri','Sat','Sun'}));
for i=1:length(day)
nr(i) = daynr(day(i));
end
Star Strider
Star Strider 2021년 9월 24일
As always, my pleasure!
.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by