필터 지우기
필터 지우기

How to separate month and year?

조회 수: 1 (최근 30일)
Megan Mirkhanian
Megan Mirkhanian 2020년 1월 20일
댓글: Megan Mirkhanian 2020년 1월 20일
Hi,
I have two columns of
  1. year and month data
  2. sand data
The year and month data looks like this 199701, so I want to make a column for the month 01 and a seperate column for the year 1997.
How will I seperate this.

답변 (1개)

Claudio Iturra
Claudio Iturra 2020년 1월 20일
편집: Claudio Iturra 2020년 1월 20일
Hello, you can run the follow example, using num2str to create a string, choose specific element of your vector and then go back with str2num.
x = [199701 199702]' % your time vector yyyyday
x = num2str(x)
year = x(:,1:4)
day = x(:,5:end)
year = str2num(year)
day = str2num(day)
year =
1997
1997
day =
1
2
  댓글 수: 1
Megan Mirkhanian
Megan Mirkhanian 2020년 1월 20일
Perfect, thank you. So I see you can do it individually, but how will I change that for the entire first column of my data. Seperating the first oclumn into two (month and year)

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by