Matlab 如何将每次迭代的输出保存到结构中

Matlab 如何将每次迭代的输出保存到结构中,matlab,Matlab,我有个问题。 我写了一个脚本,它的输出是B,一个数字和C,一个大小为3,3,3的矩阵 我必须在100次迭代中使用随机输入运行此脚本。每次迭代的输出是B和C。我想在每次迭代结束时将这些输出保存在名为example ST的结构中 你能怎么做?如何创建这个在每次迭代结束时用B和C填充的空结构 多谢各位 我的代码: a1=[1 0 1;0 1 1;0 0 0]; b1=[0 1 0;1 0 0;0 0 1]; c1=[0 0 0;0 0 0;1 1 0]; D=cat(3,a1,b1,c1); A=ze

我有个问题。 我写了一个脚本,它的输出是
B
,一个数字和
C
,一个大小为
3,3,3
的矩阵

我必须在100次迭代中使用随机输入运行此脚本。每次迭代的输出是
B
C
。我想在每次迭代结束时将这些输出保存在名为example ST的结构中

你能怎么做?如何创建这个在每次迭代结束时用B和C填充的空结构

多谢各位

我的代码:

a1=[1 0 1;0 1 1;0 0 0];
b1=[0 1 0;1 0 0;0 0 1];
c1=[0 0 0;0 0 0;1 1 0];
D=cat(3,a1,b1,c1);
A=zeros(3,3);
for i=1:3
for j=1:3
p1=0
p=0
idx=randperm(numel(A))
[m n]=ind2sub(size(A),idx(find((A(idx)==0),1,'first')))
s=find(D(m,n,:)==1)
for i=1:3
for j=1:3
for k=s
if D(i,j,k)~=1
p(i,j,k)=suit(i,j,k).^2
elseif D(i,j,k)==1
p(i,j,k)=0 
end
end
end
end
w=sum(sum(sum(p)))
p1=p./w
p2=p1(:,:,k)
r=rand
c=reshape(p2,1,[])
c=cumsum(c)
j=find(r<=c,1,'first')
[j1 j2]=ind2sub(size(p2),j)
g=find(D(j1,j2,:)==1)
D(j1,j2,g)=0
D(m,n,g)=1
D(m,n,s)=0
D(j1,j2,s)=1
x=D
end
a1=[1011;011;0010];
b1=[0110;1000;0101];
c1=[0 0;0 0;1 1 0];
D=类别(3、a1、b1、c1);
A=零(3,3);
对于i=1:3
对于j=1:3
p1=0
p=0
idx=randperm(努梅尔(A))
[mn]=ind2sub(大小(A),idx(find((A(idx)==0),1,'first'))
s=查找(D(m,n,:)==1)
对于i=1:3
对于j=1:3
对于k=s
如果D(i,j,k)~=1
p(i,j,k)=西装(i,j,k)。^2
elseif D(i,j,k)==1
p(i,j,k)=0
结束
结束
结束
结束
w=总和(总和(总和(p)))
p1=p/w
p2=p1(:,:,k)
r=兰特
c=重塑(p2,1,[]))
c=总和(c)
j=find(r试试这个:

% Define an empty structure
ST = struct('B', {}, 'C', {});

for i = 1:100

       % Do your computation here
       % Define the variables B and C 

       ST(i).B = B;   % Store B and C in the ith element of the structure
       ST(i).C = C;
end

希望这有帮助。

我将代码添加到我的问题中。我想迭代此代码。谢谢