フィルターのクリア

Average over particular ranges of one dimension in matrix

22 ビュー (過去 30 日間)
Alix Weidema
Alix Weidema 2021 年 6 月 7 日
回答済み: Scott MacKenzie 2021 年 6 月 7 日
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 Center および File ExchangeStatistics 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