How to separate each day of this file?

1 visualización (últimos 30 días)
Mohamed Nedal
Mohamed Nedal el 17 de En. de 2019
Comentada: Mohamed Nedal el 9 de En. de 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.

Respuesta aceptada

madhan ravi
madhan ravi el 17 de En. de 2019
Editada: madhan ravi el 17 de En. de 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 comentarios
Mohamed Nedal
Mohamed Nedal el 17 de En. de 2019
Thanks a lot. :)
Yes, I've accepted it.
Mohamed Nedal
Mohamed Nedal el 9 de En. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by