How do I call elements to the same precision
조회 수: 7 (최근 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!