How do I get the mean of always 4 columns

조회 수: 4 (최근 30일)
Antonio Melieni
Antonio Melieni 2019년 4월 15일
댓글: Antonio Melieni 2019년 4월 17일
Hi,
I have a 527040 x 16 double array
I need the row mean of always 4 clomuns
So I need the row mean of column 1:4 5:8 9:12 13:16
So I want the mean([1:4],2) and mean([5:8],2)
but i dont want to wirte it down in that way. I need an more automatic way to do it
any ideas?

채택된 답변

madhan ravi
madhan ravi 2019년 4월 15일
편집: madhan ravi 2019년 4월 15일
AA=permute(reshape(A.',4,1,[]),[2,1,3]); % where A is size 527040 X 16
AAA=squeeze(mean(AA));
% if you want to reshape it as matrix then
% reshape(AAA,size(A,1),[]) %% edit removed transpose
  댓글 수: 9
Matt J
Matt J 2019년 4월 15일
Both the permute operation and the transpose operation allocate arrays the same size as A. sepblockfun avoids this.
madhan ravi
madhan ravi 2019년 4월 15일
@Antonio:Matt‘s file exchange is Perfect why not use his solution then?

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

추가 답변 (1개)

Matt J
Matt J 2019년 4월 15일
편집: Matt J 2019년 4월 15일
One way is using sepblockfun, downloadable from here
Then you would do,
result = sepblockfun(yourArray, [1,4],'mean');
  댓글 수: 3
Catalytic
Catalytic 2019년 4월 15일
편집: Catalytic 2019년 4월 15일
@Antonio,
The only way I can Matt J's one line solution as being "too complicated" is that this is homework. So, you're not allowed to use third-party routines like sepblockfun as is, and it is a tedious matter for you to try to decipher what it is doing and adapt it to your assignment.
Antonio Melieni
Antonio Melieni 2019년 4월 17일
@Matt
Thanks for your function and your help.
Will use your sultion :)

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

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by