views:

52

answers:

1

hey guys, I got some difficulty here. It is purely coding algorithm problem. Okay, the program is shown below:

for f=1:(nFrames-1)
    h=histogram(imgYuv(:,:,1,f));
    j=histogram(imgYuv(:,:,1,f+1));
    X=abs(h-j)/256; %normalize the difference
    S=sum(X);
end

Basically, I want to calculate the difference between two adjacent elements and store the sum result in an 1-D array S. But the result I got from the above program is one single number. I expected it to be an 1-D array because f is varying from 1 to nFrames-1. Can anybody help me with this? Thank you!

A: 

The last line of the for-loop should be:

for f=1:(nFrames-1)
    %# ...
    S(f) = sum(X);
end

assuming the vector S is already preallocated: S = zeros(nFrames-1,1);

Amro
Thanks Amro. That works!
appi