How do I Average across structure

조회 수: 2 (최근 30일)
Rene Sebena
Rene Sebena 2018년 8월 29일
답변: Image Analyst 2018년 8월 30일
I have a 14 subject structure (ERP_data.ERP_data); for each subject there is 3D matrix: 32(electrode) x 381(data) x 32(condition); I would like to average the data across subjects with nanmean, so the final matrix will be 32x381x32; thank you for you help!
R
  댓글 수: 3
madhan ravi
madhan ravi 2018년 8월 29일
Where’s the data file?
Rene Sebena
Rene Sebena 2018년 8월 29일
Sorry, but datafile is too big to upload...you can see the structure of that file on the picture.

댓글을 달려면 로그인하십시오.

채택된 답변

Jacob Ward
Jacob Ward 2018년 8월 29일
Here's a possible solution I used to solve your problem:
clear; close all;
% This part just creates dummy data similar to yours with the same structure
ERP_data(14) = struct('ERP_data',0);
for n = 1:14
ERP_data(n) = struct('ERP_data',rand(32,381,32));
end
averagedData = zeros(32,381,32); % Initializes final matrix
for n = 1:32
for m = 1:381
for o = 1:32
dataToAverage = zeros(14,1); % Initializes vector to average
for p = 1:14
dataToAverage(p) = ERP_data(p).ERP_data(n,m,o); % Grabs the data point from each subject for the position given by m,n, and o
end
averagedData(n,m,o) = nanmean(dataToAverage); % Averages those points and then assigns that value to the position given by m,n, and o in the final matrix
end
end
end
Hope that helps!
  댓글 수: 1
Rene Sebena
Rene Sebena 2018년 8월 29일
Thanks a lot! This is what I did meanwhile, and it is also working:
GA_ERP_cue = []; for ch = 1:32 GA_ERP_cue_temp = nanmean([ERP_data(1).ERP_data(ch,:,:); ERP_data(2).ERP_data(ch,:,:); ERP_data(3).ERP_data(ch,:,:); ERP_data(4).ERP_data(ch,:,:); ERP_data(5).ERP_data(ch,:,:); ERP_data(6).ERP_data(ch,:,:); ERP_data(7).ERP_data(ch,:,:); ERP_data(8).ERP_data(ch,:,:); ERP_data(9).ERP_data(ch,:,:); ERP_data(10).ERP_data(ch,:,:); ERP_data(11).ERP_data(ch,:,:); ERP_data(12).ERP_data(ch,:,:); ERP_data(13).ERP_data(ch,:,:); ERP_data(14).ERP_data(ch,:,:)]); GA_ERP_cue(ch,:,:) = GA_ERP_cue_temp; end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 8월 30일
You can use mean() with the 'omitnan' option.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by