How to calculate 8 days mean from ten years data?
Mostra commenti meno recenti
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 Commenti
Mathieu NOE
il 20 Lug 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
il 20 Lug 2023
Devendra
il 20 Lug 2023
Cris LaPierre
il 20 Lug 2023
Mathieu NOE
il 20 Lug 2023
Modificato: Mathieu NOE
il 20 Lug 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
il 21 Lug 2023
my pleasure !
glad it works
Mathieu NOE
il 21 Lug 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
il 21 Lug 2023
Risposta accettata
Più risposte (1)
Mathieu NOE
il 21 Lug 2023
Spostato: Mathieu NOE
il 21 Lug 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 Commento
Devendra
il 23 Lug 2023
Categorie
Scopri di più su Get Started with MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!