元胞数组的非空大小信息
在 MATLAB 中,我想在容器中保留一个包含顶点 (x,y) 的折线列表,我认为最好的想法是为此使用元胞数组任务。每条线都表示为元胞数组中的一行,顶点 (x,y) 为元胞的元素。不同的线有不同的长度,这就是为什么我认为使用元胞数组是个好主意。
然而,我的问题是我不知道如何附加到单元格数组中每行的第一个非空元素?
这是一个示例:
cell{1,1} = 1
cell{2,1} = 2
cell{3,1} = 3
cell{2,2} = 4
cell{2,3} = 5
cell =
[1] [] []
[2] [4] [5]
[3] [] []
例如现在我想附加一个将新元素添加到第 1 行的末尾,将另一个元素添加到第 2 行的末尾。 我如何知道可以追加新元素的第一个位置是什么?
或者 shell 我在内部使用元胞数组元胞数组用于此任务?
如何为 MATLAB 折线列表实现容器?
In MATLAB I would like to keep a list of polylines - containing vertices (x,y) - in a container and I thought the best idea is to use cell arrays for this task. Each line would be represented in a row in a cell array, with vertices (x,y) being the elements of the cells. The different lines would be of different length, that's why I thought it would be a good idea to use cell arrays.
My problem however is that I don't know how can I append to the first non-empty element of each row in a cell-array?
Here is an example:
cell{1,1} = 1
cell{2,1} = 2
cell{3,1} = 3
cell{2,2} = 4
cell{2,3} = 5
cell =
[1] [] []
[2] [4] [5]
[3] [] []
For example now I want to append a new element to the end of row 1, and another one to row 2. How do I know what is the first position where I can append a new element?
Or shell I use cell arrays inside cell arrays for this task?
How would you implement a container for a list of polylines MATLAB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于您遇到的问题来说,这是一种糟糕的数据存储方式。有几点需要注意:
有两种好方法可以存储所有这些信息。
元胞数组:就像 Clement 指出的那样,这很好且简单,并且可以让您沿着第二个维度在同一折线中堆叠不同的点。
结构数组:如果您想将折线级元数据与点一起存储,这是一个不错的方法。
This is a bad way to store your data, for the very problems you're encountering. A couple notes:
There are 2 good ways to store all this information.
Cell array: Like Clement pointed out, this is nice and simple, and will let you stack different points in the same polyline along a second dimension.
Structure array: This is a nice way to go if you want to store polyline-level metadata along with your points.
要回答您的第一个问题,您可以使用以下方法:
使用
[...]
将单元格切片视为数组而不是几个标量值。To answer your first question, you can use this:
With
[...]
you treat the cell slice as an array and not several scalar values.