How do I append a row average to a new matrix

조회 수: 2 (최근 30일)
hbcukid
hbcukid 2021년 2월 22일
댓글: hbcukid 2021년 2월 22일
I have a 500x500 size matrix and I am trying to get the average of every 5 values in a row to make it a 100x100 matrix. How do I do that?
foo = randi(500,500)
  댓글 수: 3
per isakson
per isakson 2021년 2월 22일
편집: per isakson 2021년 2월 22일
"every 5 values in a row" that will give you a <500x100> matrix. Do you mean: and every five values in each column? Like average of every <5x5> submatrix.
hbcukid
hbcukid 2021년 2월 22일
@per isakson Im so sorry, yes thats what I mean.

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

채택된 답변

per isakson
per isakson 2021년 2월 22일
With a little bit of guessing. Does this answer your question?
%%
foo = randi(500,500);
cac = mat2cell( foo, 5*ones(100,1), 5*ones(100,1) );
num = cellfun( @(sub) mean(sub(:)), cac );
num is <100x100>

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by