如何取以下 4D 数组 (31x6x2x3) 的中位数?

How to take the median of the following a 4D array (31x6x2x3)?

我正在尝试获取以下 4D 数组中相同列的每一行的中位数:

df = randn(31,6,2,3)

我基本上有 31 行 (i) 的 6 个变量 (j) 用于两次冲击 (k),所有这些重复 3 次 (n)。现在,关注第一个冲击并得到一个 31x6x3 阵列:

eg1 = squeeze(df(:,:,1,:)) %31x6x3
  

我想得到的是同一列每一行的中位数:例如3 次重复的第一列的第一行,然后是 3 次重复的第一列的第二行,等等。这样更容易看到:

% median of every row of the first column in the 3 repetitions

median(eg1(1,1,:))
median(eg1(2,1,:))
median(eg1(3,1,:))

...

median(eg1(31,1,:))

% median of every row of the second column in the 3 repetitions

median(eg1(1,2,:))
median(eg1(2,2,:))
median(eg1(3,2,:))
...
median(eg1(31,2,:))

% basically the median of every row of the same column for every column
  

应对电击 1 和 2 执行此操作。

谁能帮我解决这个问题?

你要的是最后一个维度的中位数。 median 接受所需维度作为输入。

out=median(eg1,3)

out 将是一个 31x6 矩阵。

如果您想要所有 egx 中的那个,您只需要最后一个维度的中位数

out=median(df,4)