Borrar filtros
Borrar filtros

How to find average of every 1024th row in a vector of 61441 rows? The result should be a 60 x 1 matrix.

1 visualización (últimos 30 días)
%The Vector name is fx. I want to convert a 61441 x 1 matrix to 60 x 1 matrix such that each value in new matrix is average of 1024 rows in original matrix.

Respuestas (2)

chicken vector
chicken vector el 5 de Mayo de 2023
Have a look at reshape and mean.

Venkat Siddarth
Venkat Siddarth el 5 de Mayo de 2023
Editada: Venkat Siddarth el 5 de Mayo de 2023
Hi @Rishi,
From the context,I understand that you want to convert a 61441x1 matrix to 60x1 matrix,such that each value is a mean of 1024 rows,here assuming that number of elements is 61440 but not 61441 since it is not a multiple of 1024 ,this can be solved as follows:
% create a sample 61440 x 1 matrix
fx = rand(61440, 1);
size(fx)
ans = 1×2
61440 1
% reshape the matrix into a 1024 x 60 x 1 matrix
fx_reshape = reshape(fx, 1024, 60, []);
size(fx_reshape)
ans = 1×2
1024 60
% take the mean of each 1024 x 60 slice along the first dimension
fx_mean = mean(fx_reshape, 1);
size(fx_mean)
ans = 1×2
1 60
% reshape the resulting 1 x 60 x 1 matrix into a 60 x 1 matrix
fx_final = reshape(fx_mean, [], 1);
size(fx_final)
ans = 1×2
60 1
I hope this resolves your query,
Regards
Venkat Siddarth V

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by