Read CSV with yyyyMMddhhmmss and group months
1 回表示 (過去 30 日間)
古いコメントを表示
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.
4 件のコメント
Stephen23
2022 年 1 月 10 日
編集済み: Stephen23
2022 年 1 月 10 日
@Lauren: what version of MATLAB are you using?
" I'm simply trying to group each line by month."
Which of these to you want?:
- group by month only (so you will get twelve groups, i.e. 2021-03 is in the same group as 2019-03)
- group by month of every year (i.e. 2021-03 is in a different group from 2019-03).
What do you want to occur with missing data? For example, such as here:
Note that your description does not match the uploaded file:
yyyyMMddhhmmss % your description.
202009090029 % actually in the file (no seconds).
採用された回答
Stephen23
2022 年 1 月 11 日
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')
その他の回答 (1 件)
KSSV
2022 年 1 月 9 日
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 件のコメント
参考
カテゴリ
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!