0

I am currently writing the code in order to collect the average value for centroids coordinate inside a while loop for each video frame. For each loop cycle there will be only one average value as the output for each single frame. My objective is to collect all the average values and plot it out.

for object = 1:length(centroid);

        centX = centroid(1,object); 
        centY = centroid(2,object);    
        vidIn = step(htextinsCent, vidIn, [centY centX], [centY-6 centX-9]); %this line is for coordinate display purpose on each frame

end   

for object =   length(centroid)>0;   

        columncentroid=centroid';
        average=mean(columncentroid);
end

I am having difficulty to list all the average values from all the frames at the end of code run.The earlier average value is replaced by latest value after each loop. Kindly advice me for appropiate steps. Thank you in advanced.

4

2 回答 2

0

要保持所有平均值,您可以编写:

average = []; %init average as empty
for object = length(centroid):-1:1;   

    columncentroid=centroid';
    average= [average mean(columncentroid(:,object))]; %add new average to the end of average array
end
于 2013-04-22T05:48:06.697 回答
0

看来您已经有一个 2xN 的质心值数组;您所要做的就是展示它们。如果你想得到所有值的平均值,你可以

average = mean(centroid');

这取第一个维度的平均值 - 在转置之后是第一列中的所有 X 值和第二列中的 Y 值。average在此操作之后应该是一个 2 元素行向量。

display(average);

会告诉你值是什么。

看来这就是您想要的,并且您做的一切都是正确的(除了围绕它的那个莫名其妙的循环......)如果这不是您需要的,请在您的问题中更清楚地解释!

于 2013-04-22T04:54:19.793 回答