필터 지우기
필터 지우기

using a for loop to find the mean of a set of data

조회 수: 1 (최근 30일)
Kacey Lange
Kacey Lange 2022년 7월 26일
댓글: Matt J 2022년 7월 26일
I am trying to use a for loop to find the mean of of the first and eigth row of data, second and ninth row of data, third and tenth row of data, ect ect until I reach the seventh and fourteeth row of data. I have a 84x1 double and so my output i am expecting is a 42x1 double as I have 6 sets of data. I have tried somethign similar to this:
out = splitapply(@mean,TSMo,ceil((1:numel(TSMo))'/7));
My matrix is TSMo. But that averages every 1-7 rows.

채택된 답변

Matt J
Matt J 2022년 7월 26일
편집: Matt J 2022년 7월 26일
out = mean( reshape(TSMo,7,2,6) ,2);
out=out(:);
  댓글 수: 3
Kacey Lange
Kacey Lange 2022년 7월 26일
Right now I have six sets of data, but I am currently collecting more. Is there another way I could get this same outcome without changing this lien of code everytime I have new data?
Matt J
Matt J 2022년 7월 26일
Assuming the magic jump interval is always 7, you can do,
out = mean( reshape(TSMo,7,2,[]) ,2);
Otherwise, you must add parameters to your code for the jump interval.

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

추가 답변 (1개)

David Hill
David Hill 2022년 7월 26일
T=randi(100,84,1);
m=mean(reshape(T,7,[]),2);

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by