1、多维数组
第三维称为页,需要注意的是每一页存放的二维数组维度要一致,也就是行列数要一致。。。
a=[1,2;
3,4];
b=[2,2;
5,6];
A(:,:,1)=a;
A(:,:,2)=b;
A(:,:,3)=a;
这样就得到的A三维数组为2*2*3double
2、结构体数组
(我学这个的目的是为了将不同维度的二维数组存放在一块,将不同的二维数组赋值给新的数组,方便循环遍历)
结构体数组定义--赋值方式或者用struct
a=[1,2;
3,4];
b=[1,2;
5,6;
7,7];
gmmdata(1)=struct('cluster',a);
gmmdata(2)=struct('cluster',b);
gmmdata(1)
c=gmmdata(1).cluster
text(1).cluster=a;%cluster为结构体中一个名字
text(2).cluster=b;
text(2)
d=text(2).cluster
运行:
ans =
cluster: [2x2 double]
c =
1 2
3 4
ans =
cluster: [3x2 double]
d =
1 2
5 6
7 7
结构体数组循环输出-for循环
n=length(gmmdata);
for i=1:n
temp=gmmdata(i).cluster
end
运行:
temp =
1 2
3 4
temp =
1 2
5 6
7 7
得嘞,这就是我想要的效果,哦啦