我想创建一个以动态变量命名的结构。就像是:
for t = 1:2
for b = 1:70
Father.t.b.A = A;
Father.t.b.C = C;
end
end
当看Father
有Father.1.1.A
, Father.1.2.A
, ... , Father.2.70.C
.
谢谢你的帮助。
我想创建一个以动态变量命名的结构。就像是:
for t = 1:2
for b = 1:70
Father.t.b.A = A;
Father.t.b.C = C;
end
end
当看Father
有Father.1.1.A
, Father.1.2.A
, ... , Father.2.70.C
.
谢谢你的帮助。
MATLAB 允许使用与其他数组类似的索引结构数组:
for t = 1:2
for b = 1:70
Father(t, b).A = A;
Father(t, b).C = C;
end
end
您可以使用以下示例创建struct
(如提到的 excaza,不允许以数字开头的字段名称):
A = 1;
C = 3;
for b = 1:7
Father.(['b', num2str(b)]) = struct('A', A, 'C', C);
end
现在:
Father.b1.A
等于 1
Father.b5.C
等于 3