How to solve the problem that the demeaning of X gives a variable Y that has not exactly a zero mean, probably due to very small values ?

15 ビュー (過去 30 日間)
Hello together, I have the problem that I want to standardize a vector X. I do this by firstly demeaning X.
if true
% Y=(X-mean(X))
end
However now I have the problem that the mean of Y is not exactly zero like it should be, but really close to zero like 1.8*e-18. I attached the values of X as a file here. If I only considereing the first 6 values of X its fine
Y=(X(1:6)-mean(X(1:6)),
mean(Y)=0
but if I include the really small value of X(7), I get this different result.
if true
% Y=(X(1:7)-mean(X(1:7)),
mean(Y)=1.8e-10
end
Does anybody of you know what matlab is doing here? (rounding problem, too small number...)

採用された回答

Sam Cook
Sam Cook 2018 年 6 月 13 日
This is a result of the accuracy of floating-point numbers. If you need to account for this, you can use the eps function to determine the degree of accuracy you are working with.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by