Average over particular ranges of one dimension in matrix

40 次查看(过去 30 天)
Hi guys,
As a beginner I'm working with neural data in Matlab and I was hoping someone could help me with the following:
I have a matrix of the following size: 22 x 40 x 24 x 24 (22 dyads/subject pairs, 40 frequencies, 24 electrodes subject 1, 24 electrodes subject 2).
Now I want to average over particular ranges in the second dimension (frequencies) in the following ranges:
  • 1 - 3 (delta)
  • 4 - 7 (theta)
  • 8 - 13 (alpha)
  • 14 - 30 (beta)
My second dimension consists of frequencies 1 - 40, so I want to extract only the first 30 frequencies, divided in the ranges specified above.
So, as far as I understand I want to reduce the size of my matrix by reducing the second dimension of my matrix from 40 to 4 values, through averaging. I hope I explained it well and someone could help me with this! Thank you very much in advance :)

采纳的回答

Chunru
Chunru 2021-6-7
编辑:Chunru 2021-6-7
x = rand(22, 40, 24, 24); % your input data
y = zeros(22, 4, 24, 24); % initialize your output
y(:, 1, :, :) = mean(x(:, 1:3, :, :), 2); % average over 2nd dim
y(:, 2, :, :) = mean(x(:, 4:7, :, :), 2); % average over 2nd dim
y(:, 3, :, :) = mean(x(:, 8:13, :, :), 2); % average over 2nd dim
y(:, 4, :, :) = mean(x(:, 14:30, :, :), 2); % average over 2nd dim

更多回答(1 个)

Scott MacKenzie
Scott MacKenzie 2021-6-7
% test data
data = rand(22,40,24,24);
% make the 2nd dimension the 1st dimension
d1 = permute(data,[2 1 3 4]);
% compute means by frequency range
delta = mean(mean(d1(1:3,:), 2))
theta = mean(mean(d1(4:7,:), 2))
alpha = mean(mean(d1(8:13,:), 2))
beta = mean(mean(d1(14:30,:), 2))

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by