How do I Average across structure
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Rene Sebena
le 29 Août 2018
Réponse apportée : Image Analyst
le 30 Août 2018
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 commentaires
Réponse acceptée
Jacob Ward
le 29 Août 2018
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!
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!