2017-02-26 4 views
-2
for i=1:length(blocks) 
    for j=1:length(blocks) 
     temp = blocks{i,j}; 
     s = regionprops(temp, 'Centroid'); 
     centroids= cat(1,s.Centroid); 
    end 
end 

ために使用したとして、私は、ループのためにこれらの外に「重心」を表示すると、それだけで私は重心がによってそれらを1つずつ追加することによって、すべての繰り返しの結果を維持することができますどのように、最後の反復値を示しregionpropsの結果を格納する方法1。AA行列がループ

例:

itration-1: 4,2

itration-2: 6、4

itration-3: 1、3.2

itration-4: 2、2.5

centroids = 
[4 2; 
6 4; 
1 3.2; 
2 2.5]; 

しかし、どのような結果のみ最後の反復値2,2.5であるように私が得られるように。どのように私は次のように、配列の末尾にcentroidsを連結することができます

答えて

0

すべての反復からのすべての値を保つことができます。

centroids_arr = []; %Initialize centroids array to empty array. 

for i=1:length(blocks) 
    for j=1:length(blocks) 
     temp = blocks{i,j}; 
     s = regionprops(temp, 'Centroid'); 
     centroids= cat(1,s.Centroid); 

     %Concatenate last value of centroids to the end of centroids_arr array (insert as new row to the bottom). 
     centroids_arr = [centroids_arr; centroids]; 
    end 
end 
関連する問題