Matlab:具有6x6矩阵的结构-如何获取整个组的平均值 [英] Matlab: Structure with 6x6 matrices - how to get the average across the group
问题描述
我有一个名为数据"的结构,其中包含100个条目,每个条目对应于一个实验的参与者. 100个条目中的每个条目都包含多个提供不同值的6x6矩阵.
I have a structure named 'data' with 100 entries, each corresponding to a participant from an experiment. Each of the 100 entries contains multiple 6x6 matrices giving different values.
例如,我的第一个参与者的矩阵示例是:
For instance, an example of a matrix from my first participant is:
data.p001.matrixCB
18.9737 17.0000 14.2829 12.4499 11.7898 10.0995
18.1384 16.0000 13.4907 11.7898 11.2250 10.3441
14.7986 12.5300 11.7898 11.7473 12.2066 9.3808
14.3527 13.4536 12.9615 13.3417 12.7279 11.7047
18.0278 17.8885 17.6068 17.4642 17.1464 16.6132
24.1661 24.7790 23.7697 23.3880 22.6495 23.8537
...这是结构中具有类似设置的100个条目之一.
...and this is one of 100 entries in the structure with a similar setup.
我想获得我100位参与者中矩阵中每个单元的平均值.因此,我将获得位置矩阵CB(1,1)以及矩阵中所有其他位置的100个值的平均值.不幸的是,我看不到它是如何完成的,并且帮助功能远没有帮助.任何帮助将不胜感激!
I'd like to get the mean average value for each cell in the matrix across my 100 participants. So I would have a mean value for the 100 values in position matrixCB(1,1), and all other positions in the matrix. Unfortunately I can't see how this is done, and the help functions are less than helpful. Any assistance would be greatly appreciated!
推荐答案
结构可能很麻烦.为避免输入大量代码,您可以采用以下方法:
Structures can be a pain. To avoid typing out a bunch of code, you could take the following approach:
- 将所需矩阵转换为单元格数组
- 将单元阵列重塑为3D矩阵
- 计算平均值在3D维度上
此代码:
Mcell = arrayfun(@(x) data.(sprintf('p%03d',x)).matrixCB, 1:100, 'uni', 0);
M = mean( reshape(cell2mat(Mcell), 6, 6, []), 3 );
这篇关于Matlab:具有6x6矩阵的结构-如何获取整个组的平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!