필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
gd
gd 2020년 4월 5일
댓글: Geoff Hayes 2020년 4월 6일
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.

채택된 답변

Geoff Hayes
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
gd
gd 2020년 4월 5일
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!
Geoff Hayes
Geoff Hayes 2020년 4월 6일
Glad to have been able to help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by