Azzera filtri
Azzera filtri

Average over particular ranges of one dimension in matrix

22 visualizzazioni (ultimi 30 giorni)
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 :)

Risposta accettata

Chunru
Chunru il 7 Giu 2021
Modificato: Chunru il 7 Giu 2021
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

Più risposte (1)

Scott MacKenzie
Scott MacKenzie il 7 Giu 2021
% 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))

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by