How to separate each day of this file?

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

madhan ravi
madhan ravi il 17 Gen 2019
Modificato: madhan ravi il 17 Gen 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 Commenti
Mohamed Nedal
Mohamed Nedal il 17 Gen 2019
Thanks a lot. :)
Yes, I've accepted it.
Mohamed Nedal
Mohamed Nedal il 9 Gen 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by