Averageing cell arrays in cell array

조회 수: 2 (최근 30일)
Tim Kreitzberg
Tim Kreitzberg 2021년 3월 2일
댓글: Tim Kreitzberg 2021년 3월 2일
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.

채택된 답변

Jan
Jan 2021년 3월 2일
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.
  댓글 수: 1
Tim Kreitzberg
Tim Kreitzberg 2021년 3월 2일
Thank you Jan!
The last paragraph was just for explanation, where the idea of the question came from. Thougth maybe someone knows a trick in MATLAB I haven´t learned yet.
Since the execution time seems to be slower I will stick to creating the data earlier in the code.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by