How to separate each day of this file?

1 次查看(过去 30 天)
Hello,
Kindly find the attached text file. It contains data for the entire January 2014.
Each row represents a data record per hour so that it starts from hour=0 (the 3rd column) to hour=23 and then starts again from hour=0 for the next day, and so on.
I need to loop over the rows and save each day (24 hours; rows) separately in a text file (i.e. d1, d2, ..., d31).
Could you please tell me how to do that?
Thanks in advance.

采纳的回答

madhan ravi
madhan ravi 2019-1-17
编辑:madhan ravi 2019-1-17
T=load('Jan.txt');
TT=mat2cell(T,repmat(24,numel(unique(T(:,2))),1));
for i = 1:numel(unique(T(:,2)))
dlmwrite(sprintf('file%d',i),TT{i},'precision','%.2f','delimiter',' ') % saves each day in a separate file , filenames will be like file1.txt ... and so on till the end
end
  4 个评论
Mohamed Nedal
Mohamed Nedal 2019-1-17
Thanks a lot. :)
Yes, I've accepted it.
Mohamed Nedal
Mohamed Nedal 2020-1-9
Hi Ravi, i hope you're fine.
Please I would like to ask you one more question.
Kindly find the attached file. It's similar to the previous file (Jan.txt), but it's for the whole year of 2018 (includes all months).
I need to do the same thing as you did, but to separate each month in a separate file and then I will apply your previous code on each one to separate each month into days.
Could you tell me how to separate the whole year into months?
The issue is some months have 30 days, some have 31 days, and April sometimes has 28 days or 29 days.
I really appreciate your help.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

产品


版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by