How to use str2num function to extract a specific year from the array?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi!
I have a column matrix consists of string arrays. It's a huge time matrix and I am just showing a part of it. It contains data from year 2001 to 2019.
'2003-09-30T20:32:34Z'
'2003-09-30T20:47:34Z'
'2003-09-30T21:02:34Z'
'2003-09-30T21:17:34Z'
'2003-09-30T21:32:34Z'
'2003-09-30T21:47:34Z'
'2003-09-30T22:02:34Z'
'2003-09-30T22:17:34Z'
'2003-09-30T22:32:34Z'
'2003-09-30T22:47:34Z'
'2003-09-30T23:02:34Z'
'2003-09-30T23:17:34Z'
'2003-09-30T23:32:34Z'
'2003-09-30T23:47:34Z'
'2004-05-23T13:45:00Z'
'2004-05-23T14:00:00Z'
'2004-05-23T14:15:00Z'
'2004-05-23T14:30:00Z'
'2004-05-23T14:45:00Z'
'2004-05-23T15:00:00Z'
'2005-05-23T15:15:00Z'
'2005-05-23T15:30:00Z'
'2005-05-23T15:45:00Z'
'2005-05-23T16:00:00Z'
'2005-05-23T16:15:00Z'
'2005-05-23T16:30:00Z'
'2006-05-23T16:45:00Z'
'2006-05-23T17:00:00Z'
'2006-05-23T17:15:00Z'
'2006-05-23T17:30:00Z'
'2006-05-23T17:45:00Z'
'2007-05-23T18:00:00Z'
If I want to extract only the data from 2003, how can I select those specific rows of 2003? I personally want to use this command -
str2num(time{i}(1:4))==2003
But if there is a better alternative, I am happy to use it! Thank you so much.
댓글 수: 0
채택된 답변
Star Strider
2022년 7월 8일
C = {'2003-09-30T20:32:34Z'
'2003-09-30T20:47:34Z'
'2003-09-30T21:02:34Z'
'2003-09-30T21:17:34Z'
'2003-09-30T21:32:34Z'
'2003-09-30T21:47:34Z'
'2003-09-30T22:02:34Z'
'2003-09-30T22:17:34Z'
'2003-09-30T22:32:34Z'
'2003-09-30T22:47:34Z'
'2003-09-30T23:02:34Z'
'2003-09-30T23:17:34Z'
'2003-09-30T23:32:34Z'
'2003-09-30T23:47:34Z'
'2004-05-23T13:45:00Z'
'2004-05-23T14:00:00Z'
'2004-05-23T14:15:00Z'
'2004-05-23T14:30:00Z'
'2004-05-23T14:45:00Z'
'2004-05-23T15:00:00Z'
'2005-05-23T15:15:00Z'
'2005-05-23T15:30:00Z'
'2005-05-23T15:45:00Z'
'2005-05-23T16:00:00Z'
'2005-05-23T16:15:00Z'
'2005-05-23T16:30:00Z'
'2006-05-23T16:45:00Z'
'2006-05-23T17:00:00Z'
'2006-05-23T17:15:00Z'
'2006-05-23T17:30:00Z'
'2006-05-23T17:45:00Z'
'2007-05-23T18:00:00Z'};
DT = datetime(C, 'InputFormat','yyyy-MM-dd''T''HH:mm:ss''Z''', 'TimeZone','UTC') % Create 'datetime' Array
Y2003 = year(DT) == 2003; % Logical Vector
Result = DT(Y2003)
Result = T1(Y2003,:)
to capture all the variables in ‘T1’ for those years.
.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!