需要一些帮助来理解高维中的 MATLAB `cat` 命令
这些命令
a = magic(3);
b = pascal(3);
c = cat(4,a,b);
生成一个 3×3×1×2 数组。
为什么维度为 4
时结果是 3-3-1-2
?
The commands
a = magic(3);
b = pascal(3);
c = cat(4,a,b);
produce a 3-by-3-by-1-by-2 array.
Why is the result 3-3-1-2
when the dimension is 4
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
a
和b
都是大小为 3×3 的二维矩阵。当您沿第四维连接它们时,中间的第三维是单维(即 1)。所以c(:,:,1,1)
将是你的矩阵a
和c(:,:,1,2)
将是你的矩阵b
。这是一些文档的链接帮助理解多维数组。
编辑:
也许用我们人类更容易理解的术语来思考这四个维度会有所帮助......
让我们假设示例中的四个维度代表空间中的三个维度(
x
、y
和z
)加上第四维时间。想象一下,我在给定时间对空间中多个点的空气温度进行采样。我可以对网格中的空气温度进行采样,该网格包含三个x
位置、三个y
位置和一个z
位置的所有组合。这会给我一个 3×3×1 的网格。通常,我们可能只是说数据位于 3×3 网格中,而忽略尾随的单例维度。然而,假设我现在稍后在这些点采集另一组样本。因此,我在第二个时间点得到另一个 3×3×1 网格。如果我沿着时间维度将这些数据集连接在一起,我会得到一个 3×3×1×2 矩阵。第三个维度是单维度,因为我只对一个
z
值进行采样。因此,在示例
c=cat(4,a,b)
中,我们沿第四维连接两个矩阵。这两个矩阵是 3×3,第三维隐式假设为单维。然而,当沿着第四个维度连接时,我们最终必须通过将其大小列为 1 来明确表明第三个维度仍然存在。Both
a
andb
are two-dimensional matrices of size 3-by-3. When you concatenate them along a fourth dimension, the intervening third dimension is singleton (i.e. 1). Soc(:,:,1,1)
will be your matrixa
andc(:,:,1,2)
will be your matrixb
.Here's a link to some documentation that may help with understanding multidimensional arrays.
EDIT:
Perhaps it will help to think of these four dimensions in terms that us humans can more easily relate to...
Let's assume that the four dimensions in the example represent three dimensions in space (
x
,y
, andz
) plus a fourth dimension time. Imagine that I'm sampling the temperature in the air at a number of points in space at one given time. I can sample the air temperature in a grid that comprises all combinations of threex
positions, threey
positions, and onez
position. That will give me a 3-by-3-by-1 grid. Normally, we'd probably just say that the data is in a 3-by-3 grid, ignoring the trailing singleton dimension.However, let's say that I now take another set of samples at these points at a later time. I therefore get another 3-by-3-by-1 grid at a second time point. If I concatenate these sets of data together along the time dimension I get a 3-by-3-by-1-by-2 matrix. The third dimension is singleton because I only sampled at one
z
value.So, in the example
c=cat(4,a,b)
, we are concatenating two matrices along the fourth dimension. The two matrices are 3-by-3, with the third dimension implicitly assumed to be singleton. However, when concatenating along the fourth dimension we end up having to explicitly show that the third dimension is still there by listing its size as 1.