How do I call elements to the same precision
2 次查看(过去 30 天)
显示 更早的评论
I have a large matrix of values (> 1000x1000) and I wish to select elements of desired rows and columns and then calculate the sum of them to obtain a single value. The values in the matrix have a precision of 15 decimal places, however when I call and display them in the command window, they only have a precision of 4 decimal places. How do I call them and sum them to obtain a single value of the same precision (15 decimal places) please?
Code so far:- %%Matrix file name: Scan1_reconstruction.fits
>>a = Scan1_reconstruction(1:2, 4:5) %%this then only displays 4dp not desired 15dp >>sum(a) %%this then returns 2 values, not the desired total 1 value
Thanks
1 个评论
Rik
2018-2-2
You're getting close to the precision a floating point value can provide, so it might be impossible.
Also, you are just looking at a display problem. You can display the number with fprintf('.15f',sum(partial_matrix(:))).
If you had gone to the trouble of reading the doc for sum, you would have noticed that sum operates on only one dimension of a matrix. With (:) you can force a matrix to a vector form, but this is not compatible with subindexing.
采纳的回答
Birdman
2018-2-2
The default display format is set to short, therefore you see 4 decimal places. If you want to see more, then type
format longg
and then display your variable again.
0 个评论
更多回答(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!