How to separate month and year?
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have two columns of
- year and month data
- 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.
0 个评论
回答(1 个)
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!