How for loop Store all average values in single values

I have to store single average value from input 15 frames video file? below code i have tried but i cannot get any idea ?
if true
% code
k1_stored = zeros(1,nFrames);
for k=1:nFrames
avg= mean([X;Y]); %here x and y are array coordinates values .
k1_stored(round(avg)) = round(avg);
end
end
resultant = k1_stored(k1_stored~=0);
disp(resultant);
output: Columns 1 through 13
23 26 28 29 30 31 32 33 34 35 36 37 38
Columns 14 through 26
39 40 41 51 52 53 54 55 57 58 60 62 64
Columns 27 through 39
69 70 72 73 75 76 77 78 79 81 82 83 84
Columns 40 through 42
86 91 92

 採用された回答

Image Analyst
Image Analyst 2014 年 1 月 21 日

0 投票

Let's hope that is pseudocode because X and Y are not changing in your loop. So to store the mean as a function of frame number, do this in the loop
k1_stored(k) = avg; % Store average for k'th frame in k'th element of k1_stored array.

1 件のコメント

SAMEER ahamed
SAMEER ahamed 2014 年 1 月 21 日
when i have tried like error i got it .
if true
% code
k1_stored(k) = avg;
end
In an assignment A(I) = B, the number of elements in B and I must be the
same

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 1 月 21 日

0 投票

k1_stored(k) = round(avg);

6 件のコメント

SAMEER ahamed
SAMEER ahamed 2014 年 1 月 21 日
when i have tried i got error like?
if true
% code
k1_stored(k) = avg;
end
error: In an assignment A(I) = B, the number of elements in B and I must be the same
Walter Roberson
Walter Roberson 2014 年 1 月 21 日
Then you are not calculating a single average value. Your X and your Y have multiple columns. You need to define what you want to have happen.
SAMEER ahamed
SAMEER ahamed 2014 年 1 月 21 日
編集済み: Walter Roberson 2014 年 1 月 21 日
Yes ,I have 15 frames input video file , X and Y Coordinates have multiple values, below full code result of average of X and Y Coordinates .so how to store single variable value , because of comparison of previous value ?.
if true
% code
k1_stored = zeros(1,nFrames);
for k=1:nFrames
X =[double(leftColumnX_frames) double(rightColumnX_frames) double(centroidColumn_frames) double(centroidColumn_frames) blobCentroid_frames(1)];
Y = [double(centroidRow_frames) double(centroidRow_frames) double(centroidRow_frames) double(topRowY_frames) bottomRowY_frames];
avg= mean([X;Y]); %here x and y are array coordinates values .
disp(avg);
end
end
output :
30.5000 81.0000 52.0000 35.5000 71.6083
27.5000 86.0000 54.5000 37.5000 82.4859
23.0000 83.5000 54.0000 36.5000 77.2374
27.5000 78.0000 60.0000 40.5000 79.0523
30.0000 90.5000 61.5000 51.5000 79.2326
32.0000 80.5000 55.0000 35.5000 75.9350
26.0000 83.5000 53.5000 34.5000 74.8572
32.5000 83.0000 57.5000 38.5000 75.1091
23.0000 91.5000 57.0000 40.5000 73.1437
23.0000 91.5000 57.0000 40.5000 73.1437
28.5000 82.0000 50.5000 32.5000 64.1770
32.5000 81.0000 53.5000 36.0000 69.9803
34.0000 83.5000 52.5000 35.5000 69.8479
30.0000 81.5000 52.0000 33.5000 68.7584
41.0000 83.5000 55.0000 40.0000 70.3833
Walter Roberson
Walter Roberson 2014 年 1 月 21 日
k1_stored(k,:) = avg;
SAMEER ahamed
SAMEER ahamed 2014 年 1 月 22 日
Thank's reply to me . i have tried but i got error like ? subscripted assignment dimension mismatch .so i need to store for looping all values in single variable any idea?
Walter Roberson
Walter Roberson 2014 年 1 月 22 日
Okay, so for the moment use
k1_stored{k} = avg;
notice the curly bracket instead of round bracket.
After the loop you could try
cell2mat(k1_stored)
if you get an error in doing that then there was some "avg" that was not the same length as the others.

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by