How do I call elements to the same precision

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
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
Birdman 2018년 2월 2일

1 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

D F
2018년 2월 2일

댓글:

Rik
2018년 2월 2일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by