How to calculate 8 days mean from ten years data?
Afficher commentaires plus anciens
I have a code which calculates the 8days mean from single year. It computes 45 eight days from 45X8 = 360 days and last 8days mean from remaining 5 or 6 days of the year. I wish to use this code over ten years data with the same method as mentioned in previous line. It should not jump to next year to complete last 8 days. It should start from the 1st January and finish at 31 December of each year and then keep on doing similar way so till the end of all the data. I request you all to kindly suggest me some checks in this code to run this code over a length of continuous ten years data without overlapping between years. The code is as follows
data_matrix=readmatrix('c:/data/test.csv');
start = 1:8:height(data_matrix);
stop = unique([start(2:end)-1, height(data_matrix)]);
nbins = numel(stop);
dataAverages = nan(nbins, width(data_matrix));
for i = 1:nbins
rows = start(i) : stop(i);
dataAverages(i,:) = mean(data_matrix(rows, :), 1, 'omitnan');
end
disp(dataAverages)
size(dataAverages)
% Write output as matrix in csv format
filename = 'c:/data/test_out.csv'
writematrix(dataAverages,filename);
Devendra
12 commentaires
Mathieu NOE
le 20 Juil 2023
it would help if uu share some csv files
one csv file per year or you have all data in one single csv file ?
Devendra
le 20 Juil 2023
Devendra
le 20 Juil 2023
Cris LaPierre
le 20 Juil 2023
Mathieu NOE
le 20 Juil 2023
Modifié(e) : Mathieu NOE
le 20 Juil 2023
there is no time limit that would prevent to use that code in its original state
data_matrix=readmatrix('Test.csv');
size(data_matrix) % ans = 1096 11
windowSize = 8; % 8x1
start = 1:windowSize:height(data_matrix);
stop = [start(2:end)-1, height(data_matrix)];
nbins = numel(stop);
dataAverages = nan(nbins, width(data_matrix));
for i = 1:nbins
rows = start(i) : stop(i);
dataAverages(i,:) = mean(data_matrix(rows, :), 1, 'omitnan');
end
size(dataAverages) % 137 11
what is your issue ?
Mathieu NOE
le 21 Juil 2023
my pleasure !
glad it works
Mathieu NOE
le 21 Juil 2023
I am just seing that I actually didn't post my answer in the answer section
so I am gonna move it , so you could accept it if you want !
Devendra
le 21 Juil 2023
Réponse acceptée
Plus de réponses (1)
Mathieu NOE
le 21 Juil 2023
Déplacé(e) : Mathieu NOE
le 21 Juil 2023
you can use the existing standard readlines function instead of readlog as shown above
lines = readlines('Test.csv','EmptyLineRule','skip');
but I had to add 'EmptyLineRule','skip' to avoid empty (last) line being loaded
1 commentaire
Devendra
le 23 Juil 2023
Catégories
En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!