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