필터 지우기
필터 지우기

How Can I Clearly Identify Differences? and How to Save and Display Data in Full Decimal Format?

조회 수: 1 (최근 30일)
Hi, I have 2 data and I would like to check the differences.
According to Matlab, when I minus both data, it shows differences but when I copy the data directly from the Matlab workspace and minus it in MS Excel. it appears 0 (no differences) as shown in the attachment.
May I know how to see its difference in Matlab because I can't see any differences? And how to save and see all the data in full decimal? Is there a way to make the data tally in Excel and Matlab?
Below are the codes.
clear
clc
format long
load QuestionWorkspace
Data1
Data1 =
0.998003837794450
Data2
Data2 =
0.998003837794450
% It seems like no different but why there is different value after deduct it ?
Difference_Value= Data1-Data2
Difference_Value =
2.220446049250313e-16
% How to see its different?
% However, when I copy the data in excel
% minus the both data it appears 0 ... no different...
% How to save and see all the data in full decimal?
Thanks in advance.

채택된 답변

DGM
DGM 2024년 4월 8일
편집: DGM 2024년 4월 8일
I'm going to assume that you're entering them into excel by trusting that
format long
will reveal the entire number. It won't really. You can get more digits other ways, though be aware that when changing base, you're not assured that the result actually can be represented in a finite number of digits. At some point, the results you get will just be junk.
load QuestionWorkspace
fprintf('%.18f\n',Data1)
0.998003837794449788
fprintf('%.18f\n',Data2)
0.998003837794449566
We can see that the numbers are definitely not the same, but if you had copied them from the console window using the formatting you'd used before, then you're reducing the precision enough that they are the same.
Alternatively, please consider that I haven't used Excel in a decade, and I don't use the modern tools for writing to xlsx files. If for some reason, the data were converted to single precision floats, then you'd lose enough precision that the numbers would indeed become equal.

추가 답변 (0개)

카테고리

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