存储在元胞数组中的数据可以通过多种方式进行处理,具体取决于实际数据。处理数据的最简单方法是使用一个或多个数据对其进行迭代for循环。通过使用可以更容易地实现相同的想法cellfun函数,该函数在cellarray的所有元素上调用用户指定的函数。详见cellfun.
另一种选择是将数据转换为不同的容器,例如矩阵或数据结构。根据数据,使用cell2mat和cell2struct函数。
S = cell2struct (cell, fields) ¶S = cell2struct (cell, fields, dim) ¶转换cell到一个结构体。
中的字段数fields必须与中的元素数相匹配cell按尺寸dim,即numel(fields大小cell, dim)如果dim则假定值为1。
S = cell2struct ({"Peter", "Hannah", "Robert";
185, 170, 168},
{"Name","Height"}, 1);
S(1)
⇒
{
Name = Peter
Height = 185
}
详见: struct2cell, cell2mat, struct.
版权所有 © 2024-2025 Octave中文网
ICP备案/许可证号:黑ICP备2024030411号-2