Help converting cell to matrix of doubles (Large matrix)
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
nori lam
le 18 Oct 2016
Réponse apportée : nori lam
le 19 Oct 2016
Good day Matlabbers!
I have a textfile with almost a million rows that I need to format.
What I want to do is break up a string date into a double matrix that has 3 columns of [yyyy mm dd]. I dont want to make a datevec as I need the months and day.
What I have done is able to extract the date into a new matrix but does anyone have a good suggestion on how to vectorize my code so I dont have to run a loop?
Here is my code
data = {'1991-08-09' '12:15:00' 66.0 200 '(Unchecked)' 18966.0 200 '(Unchecked).calc';...
'1991-08-09' '12:30:00' 66.0 200 '(Unchecked)' 18966.0 200 '(Unchecked).calc';...
'1991-08-09' '12:45:00' 66.0 200 '(Unchecked)' 18966.0 200 '(Unchecked).calc'};
% single row
date_short = [str2num(data{1}(1:4)),str2num(data{1}(6:7)),str2num(data{1}(9:10))];
% loop to get all date rows
date_short_loop = [];
for a = 1:3
date_short_loop(a,1:3) = [str2num(data{a}(1:4)),str2num(data{a}(6:7)),str2num(data{a}(9:10))];
end
Any suggestions are greatly appreciated :) Thanks Norris
0 commentaires
Réponse acceptée
Matthew Eicholtz
le 18 Oct 2016
I think datevec is what you want.
d = datevec(data(:,1),'yyyy-mm-dd');
d = d(:,1:3); % if you only want to keep the year, month, and day
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!