需要一些帮助来理解高维中的 MATLAB `cat` 命令

发布于 2024-08-28 03:29:10 字数 165 浏览 10 评论 0原文

这些命令

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七禾 2024-09-04 03:29:10

ab 都是大小为 3×3 的二维矩阵。当您沿第四维连接它们时,中间的第三维是单维(即 1)。所以 c(:,:,1,1) 将是你的矩阵 ac(:,:,1,2) 将是你的矩阵b

这是一些文档的链接帮助理解多维数组。

编辑:

也许用我们人类更容易理解的术语来思考这四个维度会有所帮助......

让我们假设示例中的四个维度代表空间中的三个维度(xyz)加上第四维时间。想象一下,我在给定时间对空间中多个点的空气温度进行采样。我可以对网格中的空气温度进行采样,该网格包含三个 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 and b 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). So c(:,:,1,1) will be your matrix a and c(:,:,1,2) will be your matrix b.

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, and z) 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 three x positions, three y positions, and one z 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文