2017-02-26 5 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 

Wenn ich nur außerhalb dieser „Centroide“ anzuzeigen for-Schleifen es die letzten Iteration Werte zeigt, wie kann ich Centroide alle Iterationen Ergebnisse, indem sie eine durch Anhängen halten machen ein.Wie Ergebnis regionprops speichern, wie aa Matrix for-Schleife

Beispiel:

itration-1: 4, 2

itration-2: 6, 4

itration-3: 1, 3,2

itration-4: 2, 2.5

Damit die

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

Aber was ich als Ergebnis erhalten, ist nur die letzte Iteration Werte 2,2.5; Wie kann ich alle Werte halten von allen Iterationen

Antwort

0

Sie centroids an das Ende eines Arrays verketten lassen sich wie folgt:

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 
Verwandte Themen