How to put data from different structures in one matrix?

조회 수: 2 (최근 30일)
Inti Vanmechelen
Inti Vanmechelen 2015년 12월 17일
답변: Guillaume 2015년 12월 17일
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!

채택된 답변

Guillaume
Guillaume 2015년 12월 17일
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개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by