필터 지우기
필터 지우기

I get a different mean in matlab that i got from Excel for the same input

조회 수: 10 (최근 30일)
Tiago Dias
Tiago Dias 2018년 3월 1일
댓글: Tiago Dias 2018년 3월 1일
Hello,
So my input table is A.mat, since I have NaN values in there I use nanmean for the calculation. using nanmean from Matlab or average with excel I get the same value (as expected) 52.8926514537196000. now I wanna do the calculation for example of A(3,1) - nanmean(A). (because the first are equal, as I made a logical value in excel)
From Matlab I get 7.22209082533311000, from excel I get 7.22209082533308000, why the two values are different? I made a verification in excel, the two means are the same, the only "problem" may be related to the operation "-", any ideas why
Thanks for your time.
load('A.mat');
media_mc = mean(A);
media_nan_mc = nanmean(A);
calculation = A(3,1) - nanmean(A);
  댓글 수: 1
Tiago Dias
Tiago Dias 2018년 3월 1일
For the rest os the values, the first 12 decimal numbers are equal, the problem is with the 13 and 14 decimals number...maybe some limitation on the excel side?

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2018년 3월 1일
If matlab and excel wrote a 1000 digits after the decimal point and the 999th digit differed would you still worry about the difference?
Looking at difference in the 12th digit of precision is pointless. A slightly difference in algorithm can easily result in that difference. For all intent and purpose, the two numbers are exactly the same.
You probably need to learn more about floating point numbers and their accuracy. Your next question might be why is 0.1 + 0.1 + 0.1 not equal to 0.3?
>> isequal(0.1+0.1+0.1, 0.3)
ans =
logical
0
Note that both excel and matlab are lying to you anyway. For example, they cannot store the number 0.1 exactly, they're storing its nearest representation in binary that they round to 0.1 when displaying the number.
  댓글 수: 1
Tiago Dias
Tiago Dias 2018년 3월 1일
Thanks for you answer, now i got one question.
The average of my data is 52.89265145371962 in matlab, when i copy to excel is only shows 52.8926514537196. the number "2" is ignored, any idea how to fix this?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by