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

을 위해 사용하는 것과 내가 루프이 밖에 "무게 중심"을 표시 할 때 그것은 단지 내가 무게 중심에 의해 그들에게 하나를 추가하여 모든 반복 결과를 관리 할 수있는 방법, 마지막 반복의 값을 보여줍니다 regionprops의 결과를 저장하는 방법 하나.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