元胞数组语法

发布于 2024-10-19 11:35:51 字数 314 浏览 2 评论 0原文

两个问题:

1)我发现一段代码,上面写着 cellArr{x}{y}{3,8} = 1.0;,我想知道 {3 ,8} 表示。该程序将连接图中的各个节点连接在一起。这里我们会说“在图 x 的集合中,图 y 从 3 到 8 的连接的顶点标签为 1.0”。不过,总的来说,语法 {3,8} 在 MatLab 中意味着什么?

2)这可能不是这个问题的地方,但如果我知道我总是会有顶点值,即小数/浮点数,我真的应该使用元胞数组吗?因为我知道我只会有一种数据类型,所以矩阵会更好吗?

谢谢 :)。

Two questions:

1) I've found a piece of code that says something like cellArr{x}{y}{3,8} = 1.0;, I was wondering what the {3,8} means. The program connections various nodes in a collections of connected graphs together. Here we would say that "in the set of graphs x, the graph y's connection from 3 to 8 has a vertex label of 1.0". Still, in general what does the syntax {3,8} mean in MatLab?

2) This probably isn't the place for this question but should I really be using cell arrays if I know I'm always going to be having vertex values i.e. decimals/floats. Would a matrix be better because I know I'm only going to have a single data type?

Thank you :).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

走过海棠暮 2024-10-26 11:35:51
  1. 元胞数组可以有多个维度,因此它们可以像其他索引一样使用多个下标进行索引 多维数组。语法 {3,8} 正在索引一个(可能是)二维元胞数组,获取第三行第八列中的元胞内容。

  2. 使用元胞数组有两个主要原因:存储不同类型的数据或存储不同大小的数据。假设示例中的 x 和 y 是标量索引,则 cellArr 是一个元胞数组,其中元胞由 x 索引> 包含另一个元胞数组,其由 y 索引的元胞包含一个存储顶点标签的二维元胞数组。

    现在,如果您的顶点标签都是相同的数据类型并且都只是单个非空(即不是[])值,那么最低级别的二维元胞数组可以转换为二维数值数组,您的索引将如下所示:

    cellArr{x}{y}(3,8) = 1.0; %# 注意使用 () 而不是 {}
    

    现在的问题是如何处理由 xy 索引的两组封闭元胞数组。如果可以通过 y 索引的每个单元格都包含大小和类型相同的二维数值数组,则该单元格数组可以转换为 3D 数值数组可以像这样索引的数组:

    cellArr{x}(3,8,y) = 1.0; %# 这里我选择使用 y 作为第三个维度
    

    最后,如果可以通过 x 索引的每个单元格都包含同样大小和类型相同的 3-D 数值数组,则 cellArr 可以转换为 4-D 数值数组,可以像这样进行索引:

    numArr(3,8,y,x) = 1.0;
    

    您可以根据自己的喜好更改下标的顺序(即 numArr 的尺寸),但我将 xy 放在因此,如果您要索引顶点标签的子数组,例如 numArr(:,:,y,x) ,它将以二维数组的形式返回。如果您对索引进行了排序,以便对顶点标签的子数组进行索引,例如 numArr(x,y,:,:),它将以 4 维数组的形式返回结果,其中包含两个主要的单例维度(您必须使用 SQUEEZE 等函数删除它们)。

  1. Cell arrays can have multiple dimensions, and thus they can be indexed with multiple subscripts like any other multidimensional array. The syntax {3,8} is indexing a (presumably) 2-D cell array, getting the contents of the cell in the third row and eighth column.

  2. There are two main reasons to use cell arrays: storing data of different types or storing data of different sizes. Assuming x and y are scalar indices in your example, then cellArr is a cell array with the cell indexed by x containing another cell array, whose cell indexed by y contains a 2-D cell array which stores your vertex labels.

    Now, if your vertex labels are all the same data type and are all just single non-empty (i.e. not []) values, then the 2-D cell array at the lowest level could be turned into a 2-D numeric array, and your indexing will look like this:

    cellArr{x}{y}(3,8) = 1.0;  %# Note the use of () instead of {}
    

    The question now becomes how to handle the two enclosing sets of cell arrays indexed by x and y. If every cell that can be indexed by y contains 2-D numeric arrays all of the same size and type, then that cell array could be turned into a 3-D numeric array that could be indexed like so:

    cellArr{x}(3,8,y) = 1.0;  %# Here I've chosen to use y as the third dimension
    

    Finally, if every cell that can be indexed by x contains 3-D numeric arrays that are again all of the same size and type, then cellArr could be turned into a 4-D numeric array that could be indexed like so:

    numArr(3,8,y,x) = 1.0;
    

    You could change the order of the subscripts (i.e. the dimensions of numArr) to your liking, but I put x and y at the end so that if you were to index a subarray of vertex labels like numArr(:,:,y,x) it will return it as a 2-D array. If you had the indices ordered such that you would index a subarray of vertex labels like numArr(x,y,:,:), it will return the result as a 4-D array with ones for the two leading singleton dimensions (which you would have to remove using functions like SQUEEZE).

把时间冻结 2024-10-26 11:35:51
  1. 语法 {3,8} 是元胞数组索引,就像 {x}{y} 一样。所以 cellArr 是细胞向量的细胞向量。这些单元向量之一由 {x} 索引。该元胞向量本身就是一个元胞二维矩阵向量,由 {y} 索引。最后,这个单元矩阵由{3,8}索引,即第3行第8列。
  2. 如果所有数据都是数字,那么使用 4 维数组会更好。对于您的示例,该数组将由 numericArray[x, y, 3, 8] 索引。
  1. The syntax {3,8} are cell array indices just as the {x} and {y} are. So cellArr is a cell vector of cell vectors. One of these cell vectors is indexed by {x}. This cell vector is itself a vector of cell 2d-matrices which is indexed by {y}. Finally, this cell matrix is indexed by {3,8}, i.e. the 3rd row and 8th column.
  2. If all of your data is numeric then you'd be far better off using a 4 dimensional array. For your example, this array would be indexed by numericArray[x, y, 3, 8].
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文