matlab多維數組、結構體數組


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

得嘞,這就是我想要的效果,哦啦


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM