Read CSV with yyyyMMddhhmmss and group months
9 views (last 30 days)
Show older comments
Hello! Matlab newbie, so I apologize if this is a simple question.
I've got a 5000 by 1 CSV file filled with numbers in the yyyyMMddhhmmss format. I'm simply trying to group each line by month.
Accepted Answer
Stephen23
on 11 Jan 2022
Here is one way to group by month only, ignoring empty lines of the CSV file:
str = fileread('sample.csv');
tkn = regexp(str,'^(\d{4})(\d\d)','tokens','lineanchors');
tkn = vertcat(tkn{:})
[~,~,grp] = unique(tkn(:,2),'stable')
More Answers (1)
KSSV
on 9 Jan 2022
Read about datevec. This will split the date into year, month, days etc.....from this you can apply the function unique and get them grouped.
0 Comments
See Also
Categories
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!