필터 지우기
필터 지우기

Dividing set of data into groups and evaluating the mean of each group

조회 수: 2 (최근 30일)
Mohamed Saleh
Mohamed Saleh 2018년 2월 13일
댓글: Mohamed Saleh 2018년 2월 13일
Hi. Can any body help me with the following please?. I have a set of random data like x=[-3,-10,-2,...,-7] which is up to let say 5000 values. I need to divide x into set of groups x1, x2, x3, ...,xn, where each group of x has 50 elements. Then I need to evaluate the mean of each group and compare it with the mean of the next group. Thank you in advanced.

답변 (3개)

KSSV
KSSV 2018년 2월 13일
A = rand(5000,1) ;
B = reshape(A,50,[]) ;
mean_B = mean(B,2) ;

Akira Agata
Akira Agata 2018년 2월 13일
Another way:
x = rand(5000,1);
g = repelem(1:100,50)';
avg = splitapply(@mean,x,g);
  댓글 수: 1
Mohamed Saleh
Mohamed Saleh 2018년 2월 13일
It seems like I am not getting the right value for the mean of each group. Actually I want the first group of x has the first 50 values of x then I find the mean for this group. Then the second group of x has the next 50 values of x and find the mean for this group as well and so on.

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


Image Analyst
Image Analyst 2018년 2월 13일
I'm not sure how you're defining/selecting the values to go into each group, but once you have the groups defined, then you can use grpstats() if you have the Statistics and Machine Learning Toolbox.
  댓글 수: 1
Mohamed Saleh
Mohamed Saleh 2018년 2월 13일
Actually I want the first group of x has the first 50 values of x. Then the second group of x has the next 50 elements and so on.

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

카테고리

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