How to use str2num function to extract a specific year from the array?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ashfaq Ahmed
le 8 Juil 2022
Réponse apportée : Star Strider
le 8 Juil 2022
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 commentaires
Réponse acceptée
Star Strider
le 8 Juil 2022
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!