Finding mean value through every 12 columns of nested doubles in cell
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Geoff Hayes
2020-4-5
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!