2016-04-04 50 views
0

我有一個由regionprops()創建的MATLAB結構,它返回二進制圖像的面積和質心。目前,該結構具有16對值(每個二進制塊存在的Area和Centroid對)。 我的問題是,如何返回區域符合條件的質心值?如在,返回最大區域的質心值。從條件返回結構字段值

此刻,我發現通過

maxArea = max([struct.Area]); 

返回的,其中最大面積是結構struct內的行號面積最大價值。如何使用此行號輸出最大面積對的質心值?或者有更好的方法來做到這一點?

謝謝!

回答

1

試試這個:

[maxArea, ind] = max([s.Area]); %//get the max Area, and the index 
s(ind).Centroid %//the centroid with the max area 
+0

完美!正是我想要的。謝謝 – flexcookie