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 Kommentar

Rik
Rik am 2 Feb. 2018
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.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Birdman
Birdman am 2 Feb. 2018

1 Stimme

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.

Weitere Antworten (0)

Gefragt:

D F
am 2 Feb. 2018

Kommentiert:

Rik
am 2 Feb. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by