How to put data from different structures in one matrix?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Inti Vanmechelen
am 17 Dez. 2015
Beantwortet: Guillaume
am 17 Dez. 2015
I'm working with EMG signals (data from 10 subjects for 3 motions) and when I filtered and normalized the data, I saved them in a structure. Example: EMGProcessed.(subjects{i}).(motion{k}).
Now I want to plot the average values of those EMG signals and I if I calculate the averages, I get one value for each subject, but I want to plot the averaged signal for all subjects in one plot. I can't figure out how to extract the data from the structures in a way I can get all the averages of the different subjects in one matrix.
Here's a part of my code:
Names = {'soleus_l' 'tib_ant_l' 'gas_lat_l' 'vas_lat_l' 'rect_fem_l' 'ham_lat_l'};
format = size(Names);
for k = 1:3
MeanResult.(motion{k}) = zeros(1,format(2));
StdResult.(motion{k}) = zeros(1,format(2));
for s =1:1:format(2)
Temp252 = strcmp(Names(1,s),EMG.(subjects{i}).(motion{k}).headers);
IndexSoleus = find(Temp252==1)+1;
MeanSoleus = mean(EMGProcessed.(motion{k})(:,IndexSoleus));
StdSoleus = std(EMGProcessed.(motion{k})(:,IndexSoleus));
MeanResult.(motion{k})(1,s)=MeanSoleus;
StdResult.(motion{k})(1,s)=StdSoleus;
end
end
Obviously I get an the error that matlab can't find 'motion', beacause all my structures are saved as data.subjects.motion, but now I want the average motions for all the subjects and not for each subject.
I hope my explanation is understandable!
0 Kommentare
Akzeptierte Antwort
Guillaume
am 17 Dez. 2015
I know that a lot of people advocate using dynamic field names but in my opinion they are just as bad as dynamic variable names.
Anyway, assuming that all of the fields of your root EMGProcessed structure are indeed all subjects substructures with the same subfields:
for k = 1:3
mot = structfun(@(subject) {subject.(motions{k})}, EMGProcessed); %extract each subject motions{K} into a cell array
meanmotion{k} = mean(vertcat(mot{:})); %average the rows of the cell array
end
probably does what you want.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!