Help converting cell to matrix of doubles (Large matrix)
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Matthew Eicholtz
2016-10-18
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 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!