How to separate each day of this file?

1 vue (au cours des 30 derniers jours)
Mohamed Nedal
Mohamed Nedal le 17 Jan 2019
Commenté : Mohamed Nedal le 9 Jan 2020
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.

Réponse acceptée

madhan ravi
madhan ravi le 17 Jan 2019
Modifié(e) : madhan ravi le 17 Jan 2019
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 commentaires
Mohamed Nedal
Mohamed Nedal le 17 Jan 2019
Thanks a lot. :)
Yes, I've accepted it.
Mohamed Nedal
Mohamed Nedal le 9 Jan 2020
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by