필터 지우기
필터 지우기

How do I get the sum of the averages for a specific time step?

조회 수: 1 (최근 30일)
Nesha Wright
Nesha Wright 2018년 6월 29일
답변: Nesha Wright 2018년 7월 4일
I am using: mean_time = sum(mean(mean(mean(total)))); to get the sum of the averages of a 4D matrix. How do I change this to get the sum for a specific timestep? For example, if I wanted timestep 5 or 8 specifically rather than the sum of the entire thing (which is what the above does).
  댓글 수: 2
Adam Danz
Adam Danz 2018년 6월 29일
편집: Adam Danz 2018년 6월 29일
In which of the 4 dimensions are the time steps?
When you calculate mean(total) you are taking the mean across the first dimension. So when you calculate mean(mean(total)), you are calculating the first dimension of the mean(total) array. To demonstrate that, see how the size of each dimension changes after each mean:
K>> size(total)
ans =
4 4 4 4
K>> size(mean(total))
ans =
1 4 4 4
K>> size(mean(mean(total)))
ans =
1 1 4 4
K>> size(mean(mean(mean(total))))
ans =
1 1 1 4
If you were to use squeeze() in each of the steps above you'd see the number of dimensions decrease at each step.
If you want to take the mean over a dimension other than the first, use the second input to mean(). To answer your question, it depends upon which dimension describes the time steps.
Nesha Wright
Nesha Wright 2018년 6월 29일
The time steps are the 4th dimension. So if I want the sum average of the last timestep (# 588) I would use squeeze(sum(mean(mean(mean(total))))? How do I limit it to just the 588th time step?

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

답변 (2개)

Adam Danz
Adam Danz 2018년 6월 29일
In your 4D array, if the 4th dim is time and you'd like to isolate all data from the 588th time step,
time588 = total(:,:,:,588);
which is now a 3D array of size
size(time588)
I'm not sure of your averaging methods but if you're executing
mean(mean(time588))
Then you're averaging across the 1st dimension, then averaging the averages across the 1st dimension again; all for data from time step 588.
  댓글 수: 4
Nesha Wright
Nesha Wright 2018년 7월 3일
편집: Nesha Wright 2018년 7월 3일
Thanks!! If I wanted the last full year rather than just the last month (so time step 168-180) is there a way to do this within that single line?
Adam Danz
Adam Danz 2018년 7월 4일
time588 = total(:,:,:,168:188);

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


Nesha Wright
Nesha Wright 2018년 7월 4일
thank you!

카테고리

Help CenterFile Exchange에서 Big Data Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by