How do I append a row average to a new matrix

1 vue (au cours des 30 derniers jours)
hbcukid
hbcukid le 22 Fév 2021
Commenté : hbcukid le 22 Fév 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 commentaires
per isakson
per isakson le 22 Fév 2021
Modifié(e) : per isakson le 22 Fév 2021
"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 le 22 Fév 2021
@per isakson Im so sorry, yes thats what I mean.

Connectez-vous pour commenter.

Réponse acceptée

per isakson
per isakson le 22 Fév 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>

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by