Finding mean value through every 12 columns of nested doubles in cell

1 visualización (últimos 30 días)
Hi all,
I'm struggling to adapt previous documentation to my specific case. I have variables, "d" for example below, that are 1x36 cells comprised of nested doubles of the size 771x248-ish (changes size depending on days in a month). Each double is a month's worth of data, and I am trying to find the yearly average over the course of 3 years for one location, so only looking at the values in the first row, all columns (1,:) of the variable (will adapt this to a 30 year case).
The montly average gives me a 1x36 double, which is good.
For the yearly average, I want to obtain a 1x3 double, i.e. one average per year for three years. Again, I am only concerned with the first row, all columns of each nested double in the original cell. Below is what I think the script should look like, but I am only getting one value for the answer:
d_meana = [];
for kk = 1:12:36
d_meana = mean(d{1,kk}(1,:):d{1,kk+11}(1,:));
%will compute for other variables
end
I feel like this should be simple but I'm struggling as a newbie to Matlab. Any tips woudl be greatly appreciated, thank you in advance! Let me know if this is confusing, Itried to word it best I could.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 5 de Abr. de 2020
Gabrielle - d_meanm is a 1x36 array and you want to find the average of each of the three years, then you could reshape the array so that it is a 12x3 array where each column is a years worth of data. Then just find the average of that to get your 1x3 array
numberOfYears = 3;
d_meana = mean(reshape(d_meanm,12,numberOfYears));
  8 comentarios
gd
gd el 5 de Abr. de 2020
Geoff, this works great. Thank you for taking the time to help me, I truly appreciate it. I hope you have a nice rest of your day!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by