Problem with the mean of index

조회 수: 14 (최근 30일)
Sophia
Sophia 2016년 3월 30일
편집: Sophia 2016년 3월 30일
% tr(i,j,ni) is 361*361*432
t_r = zeros(361,361,35);
ind=10:16;
for t=1:(ni/12)-1;
if t<=34
* *mean_tr* = mean(tr(i,j,ind));*
t_r(i,j,t) = mean_tr;
ind = ind + 12;
else
end
end
mean_winter_sid = mean(t_r,3);
  댓글 수: 4
Star Strider
Star Strider 2016년 3월 30일
Could it possibly be that:
mean(tr(i,j,ind))
are zero?
For example:
q = mean([-3:3])
q =
0.0000e+000
Sophia
Sophia 2016년 3월 30일
I tried
ind = 10:16;
mean_tr = mean(tr(i,j,ind));
*It is showing zeros, but this should not be the case*

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 3월 30일
You can calculate the mean without a for loop
A=rand(361,361,432);
mina=mean(A(:)) % the mean off all the matrix
min1=mean(A,1); % dimension 1
min2=mean(A,2); % dimension 2
min3=mean(A,3); % dimension 3
  댓글 수: 4
Azzi Abdelmalek
Azzi Abdelmalek 2016년 3월 30일
use
a = tr(1:361,1:361,ind);
Sophia
Sophia 2016년 3월 30일
편집: Sophia 2016년 3월 30일
Its working , thanks Azzi
ind=10:16;
for t=1:(ni/12)-1;
if t<=34
a = tr(1:361,1:361,ind);
mean_tr = mean(a,3);
t_r(:,:,t) = mean_tr;
ind = ind + 12;
else
end
end

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

추가 답변 (1개)

Chad Greene
Chad Greene 2016년 3월 30일
Do the values of indices i and j ever change?
Can you describe in words what you are trying to do? I have a feeling it can be done much more simply and efficiently without loops.
  댓글 수: 1
Sophia
Sophia 2016년 3월 30일
I have a 361*361*432 matrix that describes the 361*361 size monthly images for 36 years.. So i have 432 matrices, i am trying to find the average over just the winter months, say Oct to April (10:16)

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

카테고리

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