Calculate Mean of vector in more decimals

8 visualizaciones (últimos 30 días)
Robert Achterstraat
Robert Achterstraat el 3 de Jun. de 2024
Editada: Image Analyst el 3 de Jun. de 2024
I want to calculate the mean of a vector in more than 4 decimals. The code
A = [0,1,9];
mean(A)
ans = 3.3333
gives
ans = 3.3333
But I want 3.333333

Respuesta aceptada

Michael
Michael el 3 de Jun. de 2024
3.3333 is only the display of the variable 'ans'. The result of the calculation has better accuracy. Type
format long
and you can see the result with all significant decimals.

Más respuestas (1)

Image Analyst
Image Analyst el 3 de Jun. de 2024
Editada: Image Analyst el 3 de Jun. de 2024
It is already that.
A = [0,1,9];
format short g
m = mean(A)
m =
3.3333
fprintf('Mean with 30 decimal places is %.30f.\n', m);
Mean with 30 decimal places is 3.333333333333333481363069950021.
format long g
m = mean(A)
m =
3.33333333333333
and

Categorías

Más información sobre Filename Construction en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by