matlab - matlab中结构内的结构
问题描述
s(1) = struct('a', 2, 'b', 3)
s(1).c(1) = struct('x',4, 'y',5);
s(1).c(2) = struct('x',6, 'y',7);
s(1).c(3) = struct('x',8, 'y',9);
尝试此操作时出现错误
s(2) = struct('a', 10, 'b', 11)
Subscripted assignment between dissimilar structures.
我正在寻找一种方法来创建c(1)
,当我创建时直接创建子字段c(2)
,有没有办法做到这一点?c(3)
s(1)
解决方案
c(1)
您可以使用、c(2)
和c(3)
如下方式创建您的结构,
s(1) = struct('a', 2, 'b', 3, 'c', [struct('x', 4, 'y', 5) struct('x', 6, 'y', 7) struct('x', 8, 'y', 9)])
如果您创建s(2)
的字段需要与s(1)
. 但是,如果需要,您可以将其c
留空。s(2)
s(2) = struct('a', 10, 'b', 11, 'c', struct)
推荐阅读
- ios - 如何快速使用陀螺仪
- three.js - 如何使用 gdal 对 Float32 光栅文件进行显着压缩
- html - 从 Latex 和 Pandoc 创建的 Mathjax 中方程的标签和引用
- mysql - 从 SQL 中的匹配列连接后仅获取一条记录
- excel - 使用Powershell打开受密码保护的Excel xlsx文件并保存为没有密码的csv
- c# - 如何在不更改其内存位置的情况下将类的值复制到其他类
- c++ - 有没有办法使用 gdb 检查分段错误发生在哪里?
- python - 在不识别换行符的情况下打印列表。我不知道如何用语言表达
- node.js - npm install --no-optional 缺少必需的参数
- c# - C++ 中的“笛卡尔积”方法