stepwise mean value of array

조회 수: 2 (최근 30일)
Rica
Rica 2012년 11월 14일
Hi!
% a= [1 2 5 6 4 7......]
how to get the mean value :
mean_a =[mean(a(1),a(110)),mean(a(2),a(120)), mean(a(3),a(130))............]
thanky
  댓글 수: 2
Image Analyst
Image Analyst 2012년 11월 14일
What do you mean by mean(a(1),a(110))? Is that the mean of all elements from 1 to 110, like this: mean(a(1:110))?
Rica
Rica 2012년 11월 14일
Hi!
that means:the mean value of element 1 and element 100, nad the mean value of element 2 and element 200 an so on ..... thanks

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

채택된 답변

Jan
Jan 2012년 11월 14일
x = rand(1, 1000);
index1 = 1:10;
index2 = 100:100:1000;
result = (x(index1) + x(index2)) * 0.5;

추가 답변 (3개)

Dian Permatasari
Dian Permatasari 2012년 11월 14일
if the calculation of some matrix, you can use:
B=mean([A(1) A(2) A(3) ...])

Walter Roberson
Walter Roberson 2012년 11월 14일
N = 7; %or as appropriate
LB = 1 : N; %the lower bounds for the means
UB = (1:N)*100; %or as appropriate for the upper bound
S = cumsum(a); %the trick!
mean_a = (S(UB) - S(LB)) ./ (UB - LB + 1);

Andrei Bobrov
Andrei Bobrov 2012년 11월 14일
편집: Andrei Bobrov 2012년 11월 14일
"...the mean value of element 1 and element 100, and the mean value of element 2 and element 200 an so on..." :
k = 100:100:numel(a);
mean_a = mean(a([(1:numel(k))', k']),2);

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by