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