MATLAB Answers

How do I append a row average to a new matrix

30 views (last 30 days)
hbcukid
hbcukid on 22 Feb 2021
Commented: hbcukid on 22 Feb 2021
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 Comments

Sign in to comment.

Accepted Answer

per isakson
per isakson on 22 Feb 2021
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>

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by