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

カテゴリ

質問済み:

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