使用大括号和圆括号访问单元格元素之间的区别

发布于 2024-12-29 18:53:04 字数 222 浏览 3 评论 0原文

使用括号 () 和大括号 {} 访问元胞数组中的元素有什么区别?

例如,我尝试使用 cell{4} = []cell(4) = []。在第一种情况下,它将第 4 个th 元素设置为 [],但在第二种情况下,它擦除了单元格元素,即将单元格元素计数减少 1 。

What is the difference between accessing elements in a cell array using parentheses () and curly braces {}?

For example, I tried to use cell{4} = [] and cell(4) = []. In the first case it sets the 4th element to [], but in the second case it wiped out the cell element, that is, reduced the cell element count by 1.

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

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

发布评论

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

评论(2

ゃ人海孤独症 2025-01-05 18:53:04

将元胞数组视为常规同质数组,其元素都是cell。括号 (()) 只需访问 cell 包装器对象,而使用大括号 ({}) 访问元素则给出包含在单元格中的实际对象细胞。

例如,

A={ [5,6], 0 , 0 ,0 };

将如下所示:

在此处输入图像描述

使元素等于 []< 的语法/code> 带括号实际上是删除该元素的请求,因此当您要求执行 foo(i) = [] 时,您会删除 i-th 细胞。它不是赋值操作,而是一个 RemoveElement 操作,它使用与赋值类似的语法。

但是,当您执行 foo{i} = [] 时,您将为第 i 个单元格分配一个新值(这是一个空数组),从而清除该单元格的内容。

Think of cell array as a regular homogenic array, whose elements are all cells. Parentheses (()) simply access the cell wrapper object, while accessing elements using curly bracers ({}) gives the actual object contained within the cell.

For example,

A={ [5,6], 0 , 0 ,0 };

Will look like this:

enter image description here

The syntax of making an element equal to [] with parentheses is actually a request to delete that element, so when you ask to do foo(i) = [] you remove the i-th cell. It is not an assignment operation, but rather a RemoveElement operation, which uses similar syntax to assignment.

However, when you do foo{i} = [] you are assigning to the i-th cell a new value (which is an empty array), thus clearing the contents of that cell.

同尘 2025-01-05 18:53:04

请参阅此链接中的帮助。正如您将看到的,使用括号 () 访问会给出单元格的子集(即子单元格),而花括号 {} 会给出您尝试访问的单元格的内容。

See the help in this link. As you'll see, accessing with parentheses (), gives you a subset of a cell (i.e. a sub-cell), while curly braces {} gives you the content of the cell you are trying to access.

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