How do I append a row average to a new matrix

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 Kommentare

per isakson
per isakson am 22 Feb. 2021
If you take the average of each row you will get a <500x1> matrix. To understand, I need a more detailed description of your problem.
per isakson
per isakson am 22 Feb. 2021
Bearbeitet: per isakson am 22 Feb. 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 am 22 Feb. 2021
@per isakson Im so sorry, yes thats what I mean.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

per isakson
per isakson am 22 Feb. 2021

1 Stimme

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>

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 22 Feb. 2021

Kommentiert:

am 22 Feb. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by