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

2 次查看(过去 30 天)
%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.

回答(2 个)

chicken vector
chicken vector 2023-5-5
Have a look at reshape and mean.

Venkat Siddarth
Venkat Siddarth 2023-5-5
编辑:Venkat Siddarth 2023-5-5
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

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by