Averageing cell arrays in cell array
2 views (last 30 days)
Show older comments
Hello I is there a easy way to average cell arrays contained by another cell array?
The programm has a main variable called subject, which contains the the data eegData, where the data is split into each electrode, which contains several variations of this data like eegSpecBandPerStim
the structure for this example is like:
i = number of Electrodes
j = number of Stimulus
k = number of Spectrum Bands (Alpha, Beta,[..])
n = data -> same length for each row in k
subject.eegData{1,i}.eegSpecBandPerStim{j,k}(n)
Is there a easier way to average the data in eegSpecBandPerStim over all electrodes/eegData Cells rather than for looping through i, j and k? I saw cellfun(), but Im getting errors because of the dot structure. This would be the most complicated example, the variable also stores cell arrays with structure of 1x7.
The result should be a cell with jxk structure and all data 1xn - it would only eleminate the dimension of the electrode.
Its technicnally also possible to create a variable with avaraged EEG data and generate the different variations based on this data earlier in the code, so this would be only for cleaning up the subject variable and move all EEG related data into the eegData struct + learning purposes.
0 Comments
Accepted Answer
Jan
on 2 Mar 2021
Using loops is the direct, clean and efficient way to access nested structs.
cellfun works on cells only, not on nested structs. The code looks nicer with cellfun, but the execution time is growing remarkably.
Its technicnally also possible to create a variable with avaraged EEG data and generate the different variations based on this data earlier in the code, so this would be only for cleaning up the subject variable and move all EEG related data into the eegData struct + learning purposes
Yes, of course this is possible. But there is no chance for the readers to suggest a corresponding code, because we do not know any details.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!