matlab dataset
1 次查看(过去 30 天)
显示 更早的评论
Hallo,
I have a huge dataset, for example matrix A, and the numbers are with 15 significat digits after the point. I want to have a new matrix B where the data is with 4 significatn digits after the point of course with the correct approximation
example: if one value of the A matrix is 23.861999511718750 I want that the value in the B matrix is 23.8620 if a value is 39.934001922607420 i want it to be 39.9340 in the B matrix. Thanks in advance
Sam
0 个评论
回答(2 个)
Walter Roberson
2011-6-11
You can fool yourself with
B = round(A*10000)/10000;
but there simply isn't any real way of doing what you want in a binary floating point system. For example,
>> sprintf('%.99g\n',23.8620)
ans =
23.861999999999998323119143606163561344146728515625
This will display as the 23.8620 that you want, but what is actually stored is a binary value whose decimal equivalent is the one I show.
0 个评论
the cyclist
2011-6-11
By default, MATLAB numerical arrays are stored as double precision, with about 15 digits of precision (not necessary after the decimal point).
If you are primarily worried about the memory requirements of storing your large matrix, then you can convert that double-precision value to single precision, using the single() function. That will result in about 7 digits of precision, and about half the memory requirement.
Regardless of how the variable is stored, there are options to display it with however many digits you want. You might start with the format() command, but there are others.
If the answer is not helpful, you should provide more details about exactly what you are trying to accomplish. If the answer was helpful, please consider accepting it.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!