The way you are looping through the vectors is not element by element but rather by increasing the vector length, that is, you are comparing the following at each iteration:
A(1,1:k) B(1,1:k)
-------- --------
k=1 [2] [2.5]
=2 [2 3] [2.5 3.1]
=3 [2 3 5] [2.5 3.1 4.8]
....
At no point do you compare only 2 and 2.1!
Assuming A
and B
are vectors of identical length (and both are either column or row vectors), then you want functions std(A-B)
, mean(A-B)
, and if you look in matlab exchange, you will find a user-contributed rmse(A-B)
but you can also compute the RMSE as sqrt(mean((A-B).^2))
. As for displaying a histogram, try hist(A-B)
.
In your case:
dt = 1;
for k=1:numel(A)
stdab(k) = std(A(1,1:k)-B(1,1:k));
meanab(k) = mean(A(1,1:k)-B(1,1:k));
err(k)=sqrt(mean((A(1,1:k)-B(1,1:k)).^2));
t(k) = dt*k;
end
You can also include hist(A(1,1:k)-B(1,1:k))
in the loop if you want to compute histograms for every vector pair difference A(1,1:k)-B(1,1:k)
.