Average over particular ranges of one dimension in matrix
조회 수: 22 (최근 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 :)
댓글 수: 0
채택된 답변
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
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))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!